473,378 Members | 1,175 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Global Try/Catch statement and error handling

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
2 6930
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: thechaosengine | last post by:
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...
7
by: Dan Bass | last post by:
In a somewhat complex application, I've developed plug-in architecture and am having a problem as to when to catch general exceptions for logging purposes. In each plug-in class library, for...
5
by: Rob R. Ainscough | last post by:
Coming from VB6 to VB.NET, it appears if I opt to use the Try Catch approach I don't have any way to RESUME from within my catch statement? What I often do is resolve the problem in my catch...
5
by: OHM | last post by:
Hi everyone, I have a problem with error handling and wondered if anyone has managed to implement a global exception handling model. Is it possible to ensure that you see all exceptions before...
5
by: Patrick Dickey | last post by:
Hello, All! I'm modifying some source code that I downloaded from Planet-source-code a while back, and have a question about Try Catch statements. Basically, I'm wondering if I can do a Try with...
4
by: DavideR | last post by:
I have converted a large vb6 program with an add-in that for every routine gimme the error handling: the add-in adds one line on the head of the routine "if myerrhandle then ON ERROR GOTO...
32
by: cj | last post by:
Another wish of mine. I wish there was a way in the Try Catch structure to say if there wasn't an error to do something. Like an else statement. Try Catch Else Finally. Also because I...
2
by: tshad | last post by:
I have my error handling set up in Global.asax: Sub Application_Error(Sender As Object, E as EventArgs) In this procedure I call a function in a dll that will write out to a history file. ...
1
by: John | last post by:
Hi I have a winform app with try/catch error handling implemented in key areas. Problem is errors can occur in other areas in situations that I may not foresee. Is there a way to implemented a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.