Solved

Top level exception handling in C#

Posted on 2009-05-07
2
640 Views
Last Modified: 2013-12-17
I want to do some logging and allow the users to unwind in the event that a truly exceptional unexpected event comes up and to avoid showing the users an Unhandled Exception.  I would like to roll the changes up the call stack to the top level so I can have a full stack trace.  Here's what I've added, but it doesn't seem to be firing on exceptions.


AppDomain currentDomain = AppDomain.CurrentDomain;

                currentDomain.UnhandledException += new UnhandledExceptionEventHandler(currentDomain_UnhandledException);

                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);

 

void  Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)

            {

                   //method to call my error class

            }

 

        void currentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)

        {

            //method to call my error class

        }

Open in new window

0
Comment
Question by:busapps
2 Comments
 
LVL 13

Accepted Solution

by:
dungla earned 500 total points
ID: 24333093
0
 
LVL 1

Expert Comment

by:GhstTracker
ID: 24337526
Using .NET 2.0 you can use Application Level Events.  One of these events is OnUnhandledException  If you put your exception handling code in this event you should accomplish what you need to do.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now