A
AC
Hi All,
I have been experimenting with delegates and exceptions.
I know that when an exception occurs on a separate thread
it is saved and retrieved when EndInvoke is called, but
why can't I rethrow it?
Regards,
Example Code:
class Application
{
delegate void MyDelegate();
static void Main(string[] args)
{
Application app = new Application();
app.Start();
Console.ReadLine();
}
public void Start()
{
MyDelegate myDelegate = new MyDelegate(BadMethod);
myDelegate.BeginInvoke(new AsyncCallback
(DelegateCallback), myDelegate);
}
public void BadMethod()
{
string newstring = string.Empty;
if (newstring.Length == 0)
{
throw new ApplicationException("delegate
testing exception");
}
}
private void DelegateCallback(IAsyncResult ar)
{
MyDelegate result = (MyDelegate) ar.AsyncState;
try
{
result.EndInvoke(ar);
}
catch
{
throw;
}
}
}
I have been experimenting with delegates and exceptions.
I know that when an exception occurs on a separate thread
it is saved and retrieved when EndInvoke is called, but
why can't I rethrow it?
Regards,
Example Code:
class Application
{
delegate void MyDelegate();
static void Main(string[] args)
{
Application app = new Application();
app.Start();
Console.ReadLine();
}
public void Start()
{
MyDelegate myDelegate = new MyDelegate(BadMethod);
myDelegate.BeginInvoke(new AsyncCallback
(DelegateCallback), myDelegate);
}
public void BadMethod()
{
string newstring = string.Empty;
if (newstring.Length == 0)
{
throw new ApplicationException("delegate
testing exception");
}
}
private void DelegateCallback(IAsyncResult ar)
{
MyDelegate result = (MyDelegate) ar.AsyncState;
try
{
result.EndInvoke(ar);
}
catch
{
throw;
}
}
}