Debugger exception fallback

N

Nak

Hi there,

I'm just curious as to something. I have just added an exception
handler at the entry point to my application, within the IDE any unhandled
exceptions fallback to this and enable me to disable a dialog of my liking.
Now if I run the application outside of the IDE I recieve the standard
"Unhandled exception" dialog provided by .NET giving me the ability to
continue or quit.

I wasn't actually aware that exception handling differed in this way
outside of the IDE? Am I doing something wrong or is this normal procedure?
As my programs entry point is sub main(), surely I can just exception handle
this routine and catch any unhandled exceptions? I must have the wrong idea
about this, thanks in advance for any help!

Nick :)
 
J

Jay B. Harlow [MVP - Outlook]

Nick,
Now if I run the application outside of the IDE I recieve the standard
"Unhandled exception" dialog provided by .NET giving me the ability to
continue or quit.
It doesn't sound like you are using a Global Exception handler, what does
your Sub Main look like?
I wasn't actually aware that exception handling differed in this way
outside of the IDE?
Yes the IDE is able to stop your program exactly where the Exception is
thrown, allowing you to debug that location (check local variables & such).

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 add handler in your Main.

For Windows Forms look at:
System.Windows.Forms.Application.ThreadException event
Use add handler in your 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/issues/04/06/NET/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
 
N

Nak

Hi Jay,

Thanks for the information, that's just the ticket. I wonder how I
hadn't come across this sooner? Anyway, thanks thats great! :)

Nick.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top