locked
application_error not getting called RRS feed

  • Question

  • User283943842 posted

    Hi all,

    I have a new project and a custom error page set up. When an exception or error happens the custom error page gets called but applicatin_error in global.asax never gets called. Other subs in global.asax are working fine (application_start etc). All I have right now in application_error is a simple trace.write to say "hi I got here" so I know there is nothing in global causing a second exception. 

    Any ideas? I have this working on other apps but can't get this working on this one.

    thanks

    Sunday, September 8, 2013 5:58 AM

Answers

  • User753101303 posted

    As you are using VB what if you add a http://msdn.microsoft.com/en-us/library/6k46st1y.aspx (handles) clause to make 100% sure this event handler is attached.

    Also I assume that you have a test page that does nothing else that throws explicitely an exception when you click a button for example and that have *NO* other content except that.

    BTW if it is not called, what is the behavior you see ? Do you see the "yellow page" ? I noticed you told about a trace (but it is still possible that it runs without the trace being shown for some reason).

    What if you use a Stop statement inside this handler or put a breakpoint (and in this case put a breakpoint as well in some other global.asax procedure to make sure breakpoints are ok). If you see the "yellow page" it could be that Server.ClearError is not called.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 11, 2013 7:56 AM

All replies

  • User753101303 posted

    Hi,

    Have you double checked the procedure name ? I assume that "applicatin_error" is a typo and is NOT the real name you have in global.asax ? You may want to show what is the full signature you used...

    Monday, September 9, 2013 6:53 AM
  • User283943842 posted

    Just a typo. I'm using Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)

    thanks

    Monday, September 9, 2013 7:26 AM
  • User-166373564 posted

    Hi,

    void Application_Error(object sender, EventArgs e)
            {
                // Code that runs when an unhandled error occurs
                Exception objErr = Server.GetLastError().GetBaseException(); 
                string err = "Error Caught in Application_Error event\n" + "Error in:" 
                    + Request.Url.ToString() + "\nError Message:" + objErr.Message.ToString() 
                    + "\nStack Trace:" + objErr.StackTrace.ToString(); 
                EventLog.WriteEntry("Sample_WebApp", err, EventLogEntryType.Error); Server.ClearError();
            }
    

    I use the codes above to get error on my side, it works fine, I think it is also available for you, or you could post your codes, we will give more precise troubleshooting for you,

    Regards

    Monday, September 9, 2013 8:01 AM
  • User283943842 posted

    That's not going to work. Like I said in the first post application_error is getting even getting called.

    thanks

    Monday, September 9, 2013 8:33 AM
  • User71929859 posted

    Please note that application_error in global.asax file will only get fired for unhandled exceptions. You need to remove try catch blocks.

    Tuesday, September 10, 2013 9:51 AM
  • User283943842 posted

    Yep I'm aware of that. No try statements here. This one's doing my head in. Any other way to get the last error visible in my customer error page? It comes in as null at the moment so it's not being passed along.

    Tuesday, September 10, 2013 5:50 PM
  • User-37275327 posted

    Hope this is not a web service project. Have a look @ this.

    Wednesday, September 11, 2013 5:13 AM
  • User283943842 posted

    No just a web form apps. Think I'm going to cry Frown

    Wednesday, September 11, 2013 5:15 AM
  • User-37275327 posted

    Follow this thread, may be similar setting on your web.config.

    Wednesday, September 11, 2013 5:50 AM
  • User753101303 posted

    As you are using VB what if you add a http://msdn.microsoft.com/en-us/library/6k46st1y.aspx (handles) clause to make 100% sure this event handler is attached.

    Also I assume that you have a test page that does nothing else that throws explicitely an exception when you click a button for example and that have *NO* other content except that.

    BTW if it is not called, what is the behavior you see ? Do you see the "yellow page" ? I noticed you told about a trace (but it is still possible that it runs without the trace being shown for some reason).

    What if you use a Stop statement inside this handler or put a breakpoint (and in this case put a breakpoint as well in some other global.asax procedure to make sure breakpoints are ok). If you see the "yellow page" it could be that Server.ClearError is not called.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 11, 2013 7:56 AM