Genralized way to handle exceptions

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a generalized way to catch exceptions for a form/window? With MFC, I could implement a try/catch in an override of PreProcessMessage(..), or WndProc(..), but with Forms, those don't seem to work the same way and so the try/catch misses the exception

I'm trying to find a way to avoid implementing try/catch in every event handler for the form/window, since I handle most of them in the same way.
 
I'm trying to catch the error before it leaves the form so I can close the form but keep the application running. The ThreadException handler catches the exception at the application level when it's too late to do anything except shut down the application.
 
Bob,
No it doesn't! Herfried is correct, the Application.ThreadException event
handles exceptions that occur during the handling of an event, I suspect you
are thinking of the AppDomain.UnhandledException event.

Depending on the type of application you are creating, .NET has three
different global exception handlers.

For ASP.NET look at:
System.Web.HttpApplication.Error event
Normally placed in your Global.asax file.

For console applications look at:
System.AppDomain.UnhandledException event
Use AddHandler in your Sub Main.

For Windows Forms look at:
System.Windows.Forms.Application.ThreadException event
Use AddHandler in your Sub Main.

Hope this helps
Jay

Bob Kirkwood said:
I'm trying to catch the error before it leaves the form so I can close the
form but keep the application running. The ThreadException handler catches
the exception at the application level when it's too late to do anything
except shut down the application.
 
Back
Top