Solved

Top level exception handling in C#

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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

707 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