Solved

Determining Exception Type

Posted on 2009-07-09
2
211 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
ID: 24816234
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
ID: 31602049
Thanks .. didn't realize it was that simple.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

803 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