Possible Duplicate:
.NET Global exception handler in console application
I’ve read a lot of things about global exception handling on stackoverflow, but I could not find anything refering to my topic properly. I wrote a console application that catches exceptions just in the methods they occur. No throw’s at all. What I want to have is a global exception handling. I no the basic guidlines about exception handling, but got no idea beyond those basics. Imaginary there should be one class handling those exceptions (thrown by the methods from the different classes). I don’t need any error-recording or error-reporting mechanisms yet. Just need the basics (patterns whatever…) to implement this global handling. Thanks for reading so far!
Handling exceptions globally is good for certain tasks only, such as logging errors or graceful exit of the application.
In all other cases, it is recommended that you handle the exception in the most relevant place. For example, if you make a web service call from your app and if the service is not available, you should handle that exception where you make the webservice call instead of catching it globally. This improves the readability of the code, and also it’s not practical to do anything sensible at global level as you have very little information on where the exception originated. (Of course you have the stack trace, but its not readily available for programmatic manipulation)
However, you can add an application wide exception handler by attaching a handler to AppDomain.UnhandledException as also indicated in the comment by @Jesse