By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,773 Members | 1,779 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,773 IT Pros & Developers. It's quick & easy.

Global Try/Catch statement and error handling

P: n/a
VM
Is it possible to intercept all exception errors into one Try...Catch? I've
tried wrapping Application.Run() in a Try...Catch, but it doesn't seem to
work all the time.

Thanks.
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

Try with Application.ThreadException event.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"VM" <vo******@yahoo.com> wrote in message
news:eW**************@TK2MSFTNGP09.phx.gbl...
Is it possible to intercept all exception errors into one Try...Catch? I've tried wrapping Application.Run() in a Try...Catch, but it doesn't seem to
work all the time.

Thanks.

Nov 16 '05 #2

P: n/a
In addition to Miha's comments.

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
"VM" <vo******@yahoo.com> wrote in message
news:eW**************@TK2MSFTNGP09.phx.gbl...
Is it possible to intercept all exception errors into one Try...Catch? I've tried wrapping Application.Run() in a Try...Catch, but it doesn't seem to
work all the time.

Thanks.

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.