Rethrowing exceptions

  • Thread starter Thread starter Coder Guy
  • Start date Start date
C

Coder Guy

I am implementing an asynchronous handler (similar to Control.EndInvoke) and
if the other thread throws an exception, I catch it and rethrow it on the
current thread. How can I rethrow the exception on the current thread while
maintaining the stack trace? The best I've come up with is encapsulating
the exception as an inner exception. I would prefer to just rethrow the
exception directly -- no need for an inner exception.

How does Control.EndInvoke handle this?

Thanks
 
Coder Guy said:
I am implementing an asynchronous handler (similar to Control.EndInvoke)
and if the other thread throws an exception, I catch it and rethrow it on
the current thread. How can I rethrow the exception on the current thread
while maintaining the stack trace? The best I've come up with is
encapsulating the exception as an inner exception. I would prefer to just
rethrow the exception directly -- no need for an inner exception.

You can rethrow the current exception writing just "throw;" instead of
"throw myNewException;".
 
I think you missed the point. The exception is saved and rethrown on
another thread, and therefore, that won't work for me...
 
Coder Guy said:
I am implementing an asynchronous handler (similar to Control.EndInvoke) and
if the other thread throws an exception, I catch it and rethrow it on the
current thread. How can I rethrow the exception on the current thread while
maintaining the stack trace? The best I've come up with is encapsulating
the exception as an inner exception. I would prefer to just rethrow the
exception directly -- no need for an inner exception.

How does Control.EndInvoke handle this?

Are you sure that Control.EndInvoke *does* handle this? Does it appear
to replace the stack trace with the original one?
 
Back
Top