?
Solved

Top level exception handling in C#

Posted on 2009-05-07
2
Medium Priority
?
651 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 2000 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

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…
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…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

752 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