By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,201 Members | 1,383 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,201 IT Pros & Developers. It's quick & easy.

Exception in a Thread other than Main thread

P: n/a
I have one program, where i am using IO and Socket Asynchronous methods
"BeginXXX" and "EndXXX".

Many time, it happens that in Async delegate method, some exception occurs
and if i dont handle it, it shows standard Unhandled exception box even I
have handled the exception using try/catch in the main thread which is
caller of that method.
That means, the exception cant be handled by catch block written in main
thread if the exception occurs in a thread other than main.

My intention is to get the exception message so i can handle it gracefully
and show a userfriendly message on that exception. So usual, i use re-throw
the exceptions and handle in main UI blocks, if its not possible to return
values or if return value is possible then as return value so in UI blocks i
can show user friendly messages.

But as mentioned above, in multi-threaded program, if such condition happens
then what is the solution?
Is it possible to do that anyhow?
Is it by design or my program has bad-design?
If this is bad design then please suggest better way,

Thanking you in Advance,
May 18 '06 #1
Share this Question
Share on Google+
2 Replies

P: n/a

System.Threading.ThreadExceptionEventHandler(Appli cation_ThreadException);


May 18 '06 #2

P: n/a
Thanks for the kool pointer.
But the problem is we have many of independent components and some of
components internally uses other components and now inner most component
class has thrown some exception in different thread [other than main thread]
then will it be caught in Main thread in Main application?
Main App [with UI] -> Comp1 -> Comp2 -> Comp3
Now if Comp3 throws an exception in diff thread then ThreadException will
catch that exception but what if i want to catch it in Comp1 or Comp2 where
i havnt not used UI [means Windows Forms] ?
This ThreadException event force me to use Windows.Forms assemly so is there
any other similar way?
Also, this is a single event method where i am getting this exception but if
i want to catch exception by caller and it may be any seperate methods so is
it possible to catch this exception in caller method somehow? because its
tough to handle all the exception in one method and who throws that
exception, how we can know if its really hugh application with lots of

Else this will be definately helpful to me.

"Tasos Vogiatzoglou" <tv*****> wrote in message

System.Threading.ThreadExceptionEventHandler(Appli cation_ThreadException);


May 19 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.