Solved

Top level exception handling in C#

Posted on 2009-05-07
2
646 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

763 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