Solved

Top level exception handling in C#

Posted on 2009-05-07
2
647 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

737 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