threads (exceptions)

  • Thread starter Thread starter csharpula csharp
  • Start date Start date
C

csharpula csharp

Hello,
I am trying to run a thread and inside this thread an exception
happenes.
The question is how can I catch the exception outside of the thread and
react on this exception?
Thank you!
 
I am trying to run a thread and inside this thread an exception
happenes.
The question is how can I catch the exception outside of the thread and
react on this exception?

You can't really *catch* it in a different thread, but you can add an
eventhandler to AppDomain.UnhandledException.

One alternative is to create a custom thread class which you pass a
ThreadStart or ParameterizedThreadStart delegate instance to, which
would then create (and expose) the CLR thread, while running the
delegate inside a try/catch. You can then do what you want with
whatever exception is thrown, and it won't bring down the CLR.

Jon
 
csharpula said:
Hello,
I am trying to run a thread and inside this thread an exception
happenes.
The question is how can I catch the exception outside of the thread
and react on this exception?
Thank you!

Catch it inside the thread, then use Control.Invoke or some other message
passing mechanism to hand the Exception instance off the the thread where
you want to process it.
 
Hello,
I am trying to run a thread and inside this thread an exception
happenes.
The question is how can I catch the exception outside of the thread and
react on this exception?
Thank you!

*** Sent via Developersdexhttp://www.developersdex.com***

You have to catch it inside the method hence inside the thread.

What is your escenario? if you give more details we might find a
better solution
 
Back
Top