Richard,
The "easiest" way would be to use one or more Global Exception Handlers,
which after logging the error causes your application to exit...
Wrapping Application.Run with a Try Catch (as Ken showed) will only catch
exceptions in the constructor of your main form.
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.
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.ThreadException 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.ThreadException handler will catch all
uncaught exceptions from any form/control event handlers.
Hope this helps
Jay
"Richard Myers" <fa**@address.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hello,
I was recently asked how to ensure an app falls over when an exception
occurs that has not been caught.
The framework will often prompt the user to Quit or continue in such case
and offer a little Stack Dump as well.
I was asked how to prevent this and just let the app die.....I didn't know
the answer...
possibly because i have yet to write anything with a bug in it..... ;)
I am assuming it is some fairly trivial setting?
Thanks
Richard