Global Error Handling...

Like there is in Asp.Net, does anybody know of a good way to do globla error handling Because right now I am having to maintain try/catch blocks around every every piece of code I write and it is a pain.

Anybody have any suggestions



Answer this question

Global Error Handling...

  • CDL

    Thanks. I knew about the thread exception part, but the appdomain part was helpful as well.


  • Stuarta670

    You don't need to write try/catch blocks around every method. Only write try/catch blocks if you intent on catching a specific exception. Here is a good guide to exception handling:

    http://www.codeproject.com/dotnet/exceptionbestpractices.asp


  • MarkD08

    Put something like this at the head of static void main:

    AppDomain currentDomain = AppDomain.CurrentDomain;

    currentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledException);

    If your app uses threads, also do this:

    Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);

    Obviously you need to write the methods as well :-) I also put a try catch around the call to Run(); in my SVM, but I regard that as legacy code from before when I learned ( on this forum actually ) about those two events.



  • Global Error Handling...