As Henk Holterman has already suggested you should handle exceptions. Only those nasty ones which are unhandled should be left for Application.ThreadException. In case you are not aware then, although you will be able to display your message in the Application.ThreadException
event handler method, the application will then terminate. Certain exceptions are not caught by Application.ThreadException
and you will have to handle AppDomain.UnhandledException
Event.
AFAIK It is best not to throw exceptions in Async handlers (gurus, correct me if I am wrong). The best way to deal with them would be to either throw exceptions when user calls end invoke or when the user tries to retrieve response objects. Please note if you throw exc
object from one thread it won't be caught in some other thread. So, to inform the main thread one way would be to raise an event (which the main thread has hooked onto) in which you pass the response object. If an error has occured then raise an exception in the getter of the response object else return the response object. Another way would be to just raise an event which would tells the main thread just about the exception.
EDIT:
Just saw your comment:
we can catch exception and redirect
page to the errorpage in asp.net by
setting the error data in web.config.
how to do in winform?
There isn't a direct way to do it in winforms. The way I do it is have one HandleError method per thread. This method will accept exception object as parameter and inspect the type of exception will display a message box and/or log it.