tce,
In addition to the other comments:
Depending on the type of application you are creating, .NET has three
different global exception handlers.
For ASP.NET look at:
System.Web.Http Application.Err or event
Normally placed in your Global.asax file.
For console applications look at:
System.AppDomai n.UnhandledExce ption event
Use AddHandler in your Sub Main.
For Windows Forms look at:
System.Windows. Forms.Applicati on.ThreadExcept ion event
Use AddHandler in your Sub Main.
It can be beneficial to combine the above global handlers in your app, as
well as wrap your Sub Main in a try catch itself.
There is an article in the June 2004 MSDN Magazine that shows how to
implement the global exception handling in .NET that explains why & when you
use multiple of the above handlers...
http://msdn.microsoft.com/msdnmag/is...T/default.aspx
For example: In my Windows Forms apps I would have a handler attached to the
Application.Thr eadException event, plus a Try/Catch in my Main. The
Try/Catch in Main only catches exceptions if the constructor of the MainForm
raises an exception, the Application.Thr eadException handler will catch all
uncaught exceptions from any form/control event handlers.
Public Shared Sub Main()
AddHandler Application.Thr eadException, AddressOf
Application_Thr eadException
Application.Ena bleVisualStyles ()
Application.DoE vents()
Try
Application.Run (New MainForm)
Catch ex As Exception
' log ex for later diagnosis
' optionally show "pretty" version to user
End Try
End Sub
Private Shared Sub Application_Thr eadException(By Val sender As Object,
ByVal e As System.Threadin g.ThreadExcepti onEventArgs)
' Log the e.Exception for later diagnosis.
' optionally show "pretty" version to user
End Sub
Hope this helps
Jay
"thechaosengine " <na> wrote in message
news:40******** *************@n ews.microsoft.c om...
| Hi everyone,
|
| Is there anyway to create some sort of catch-all in windows forms
applications
| that could ensure that no unexpected exceptions bring down an application?
|
| For example, perhaps there is an event that you can watch for whenever an
| exception is thrown? If this isnt possible can anyone suggest the best way
| to handle unforeseen exceptions? I'm assuming that surrounding huge chunks
| of application code in try catch blocks would be a programming faux pas
:-)
|
| Thanks to anyone who can offer advice
|
| Kindest Regards
|
| tce
|