Solved

Determining Exception Type

Posted on 2009-07-09
2
209 Views
Last Modified: 2013-12-17
In my application, I am using the global.asax's Application_Error to manage all unhandled exceptions -- essentially, I log the exception and redirect the user to specified error page.  

I have introduced a new entry point into my application that requires two parameters.   If either of the parameters are not available, I throw a custom exception to specifically identify this new error type.   The problem is, I'm not sure how to differentiate in the global.asax between this specific exception [I've defined it as MonthlyBreakdownException] and all other exceptions.      How can I obtain the specific error type [MonthlyBreakdownException] in my code below?

I'm using Visual Studio 2005, C#
Here is my code that I'm using currently:
 

        Exception ex = Server.GetLastError().GetBaseException();

        Logger.LogError(ex);
 

//I'd like to check for my new error here//
 

        if (Session["sessionId"] == null)

        {

            Response.Redirect("SystemTimeout.aspx", true);

        }

        else

        {

            Response.Redirect("LandingPage.aspx?sessionid=" + "none", true);

         }

Open in new window

0
Comment
Question by:escheider
2 Comments
 
LVL 12

Accepted Solution

by:
williamcampbell earned 250 total points
Comment Utility
Check the Type?
Exception ex = Server.GetLastError().GetBaseException();
 

if ( ex.GetType () == "MonthlyBreakdownException" )

{

    // Woop!

}

Open in new window

0
 
LVL 4

Author Closing Comment

by:escheider
Comment Utility
Thanks .. didn't realize it was that simple.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

762 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

6 Experts available now in Live!

Get 1:1 Help Now