How to stop excetpion bubbling in Global.asax if you have an "Error Handling Module" RRS feed

  • Question

  • User1309395204 posted

     I have an "Error Handling Module" for porcessing errors but I also have some code executed in Global.asax.

    The "Error Handling Module" is exectued first (which is fine) in it I call "Server.ClearError()" because I would like to stop the execution of other error handlers.

    I found an unexpected behaviour: the global.asax function Application_Error is executed!!!!

    Since I called "Server.ClearError()" I was expected to stop exception bubbling.

    Could somebody help me?


    Kind regards 



    Friday, January 16, 2009 4:00 AM

All replies

  • User-2121795492 posted

    Don't use the Server.ClearError(), just catch the error in a Try Catch block. You might want to try this technique on all of your database calls

    Friday, January 16, 2009 4:41 AM
  • User1309395204 posted

    I appreciate your comment but you did not understand what the real problem is.

    Kind regards


    Friday, January 16, 2009 5:33 AM
  • User-60428002 posted

    Server.ClearError() just clears the previous exception.  And it can't provent the exception bubbling.

    Thursday, January 22, 2009 1:17 AM
  • User1309395204 posted

    Thanks for your post.

    Do you know how I can stop the exception bubbling?

    I tried with folowing line of codes, but it does not work.



    Do somebody have an idea how to do it?

    Kind regards


    Thursday, January 22, 2009 3:51 AM
  • User-1392837595 posted

    I have a similar situation.  The app I am working on uses the Global.asax file for exception handling.  I am creating a new piece of the the application that I would like to handle all errors via the pages Error event. I need to keep the Global.asax file from picking up the exceptions.  How can this be done?

    Monday, November 16, 2009 3:13 PM
  • User1309395204 posted

    After 2 years I still don't have a solution. Sorry for it.

    A a workaround you might be can add to the HttpContext.Items property a value, which tells that the exception shouldn' t be handled anymore. In global.asax you look if the context contains the value and based on this information you write your logic. 

    I don' t know it this works, since I did not try it out (it is only an idea).


    Tuesday, November 17, 2009 7:32 AM
  • User213768233 posted

     Hi Chris and Daniel,

    It is important to know what it is you want to do with the exception. Do you want to stop execution of the page load? Or do you want to just log the error and move on?

    To stop execution of the page load, I have often used the Page_Error event. When an error causes the Page_Error event to fire, it usually means that the page cannot fully load and therefore cannot recover from the error. In these cases, I usually re-direct them (using Respose.Redirect) to an error page that I have created. The error page tells the user that an error has occured and if appropriate, what the error was. By re-directing at this point, the original request is terminated and a new request is made. Hence, the error never reaches the Global.asax error event. 

    If you want to catch the error and stop it from bubbling, then you should using try catch blocks to handle/log the error. These kinds of errors should be caught during database calls. Of course, if the error is caught and logged it also means that the Interface layer did not get the information that was expected. If that happens then the Page_Error event would fire. If you want to load the page regardless of errors and missing information then you need to check for null on each setting of labels, text boxes etc. In practice, it is better to alert the user that an error has occured and then for you to search for the actual cause.

    So, the solution is to program your middle tier to log the errors that occured and then to stop the execution of a page request when the error has occured during loading of the page. The re-direction to a page that lets the user know something went wrong and the logging of the error helps the support team to identify what went wrong.

    One more thing. It is best to add an AppSetting that allows you to turn off the custom error handling. You may want to let the error bubble to the global.asax in various environments (such as QA or UAT) to help test users give relevant feedback. Then you can do the following in your Page_Error function:

    If ConfigurationManager.AppSettings("EnableCustomErrors").ToLower = "true" Then
    'Redirect to Error Page
    End If
    I hope that helps!



    Wednesday, November 18, 2009 11:13 PM