Hi all,
I am trying to catch all types of exceptions from a app regardless of
whether it is in debugger mode( VS development environment) or run the.exe
file outside the IDE.
My App contains the thousand of classes and I do not want to use the Try
Catch block in each class. Because it is logically similar to GOTO
statement. I want to prevent exception from being swallowed.
I use a startup project, so that i can show the MDI main application window
within a Try Catch block. This all works fine when i run the App from within
the IDE, but when i run outside of the IDE i.e. run the .exe file. It
doesn't seem to catch the exception???
I also use both Application.ThreadException and
AppDomain.CurrentDomain.UnhandledException event in order to capture
unhandled Exceptions outside the IDE.
Now please guide me whether it is good technique for centralize way of
exception handling or I need two startup classes to handle Exception. One
for handling Exception within the IDE and one for outside the IDE.
Here is my sample code for handling all types of exception within one
startup class.
try {
Application.ThreadException += new
ThreadExceptionEventHandler(App_ThreadException);
AppDomain.CurrentDomain.UnhandledException +=new
UnhandledExceptionEventHandler(App_UnhandledExcept ion);
Application.Run();
} catch(Exception ex) {
//write nice error reporting routine!
Environment.Exit(0);
}
private static void App_ThreadException(object sender,
ThreadExceptionEventArgs e) {
//show message Box
}
private static void App_UnhandledException(object
sender,UnhandledExceptionEventArgs e) {
//show message Box
}
Hope this makes sense.
Waiting for your reply.
thanks inadvance.
Regards
Noor