Is it legal and safe in C# to catch an exception on one thread, and then re-throw it on another.
E.g. is this legal
Exception localEx = null;
Thread mythread = new Thread() { () =>
{
try
{
DoSomeStuff();
}
catch(Exception ex)
{
localEx = ex;
}
});
myThread.Start();
...
myThread.Join();
if(localEx != null)
throw localEx; // rethrow on the main thread
I think it is legal, but I'm having trouble finding any doco that proves it. The closest I found was a brief mention of transferring exceptions between threads here: http://msdn.microsoft.com/en-us/library/ms229005.aspx