Wednesday, March 28, 2012

PageError doesnt preserve stack trace


I use the ScriptManager.PageError event in order to catch internal exceptions and rethrow them to be handled by the Application_Error event, just like in any non-ATLAS page.

The problem is that ATLAS clears the exception's stack trace and restarts it only from the PageError event handler itself.

I'm having hard time resolving the problems without having the original stack trace.

Any ideas?




are you sure about this? i seem to recall cehcking for a stack of an exception during the error handling...i maybe wrong since i don't have atlas installed here and can't check it right now...

Yes, I created an exception inside a function of a UserControl I'm using in my page, and this is the stack trace of the e.Error exception returned by theScriptManager_PageError event.

As you can see, there is no stack trace before the PageError event. When not using ATLAS, the Server.GetLastError() function returns the original exception with the original stack trace as an InnerException.

at ***.Web.UI.***.TheScriptManager_PageError(Object sender, PageErrorEventArgs e) in ****.aspx.cs:line 179

at Microsoft.Web.UI.ScriptManager.OnPageError(PageErrorEventArgs e)

at Microsoft.Web.UI.ScriptManager.OnPageError(Exception ex)

at Microsoft.Web.UI.ScriptManager.OnPageError(Object sender, EventArgs e)

at System.Web.UI.TemplateControl.OnError(EventArgs e)

at System.Web.UI.Page.HandleError(Exception e)

at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


hello.'s an excerpt of a stack trace from an aspx on the error event of the scriptmanager:

at ASP.error.h(Object sender, EventArgs args) in d:\atlas\AtlasWebSite2\error.ascx:line 7
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

as you can see, the error comes from an usercontrol which is inside an updatepanel,...


My mistake. I did a "throw e.Error" in the PageError handler which, of curse, cleared the stack trace...

Thanks for your help,


I have the same problem in my page, but your post don't solve my problem. I did the same thing you did and rethrow the exception e.Error in the Script Manager PageError event hadler but the exception is again catched by the atlas framwork not by the application error handler and a popup window shows with the exception. Why is this happening?


well, if i recall correctly, scriptmanager catches all page erros and removes them so that the current request can be handled correctly. if it didn't do this, the client side would never receive the correct response (ie, the response wouldn't be in the correct format). if you need to log the error on the server, then handle the scriptmanager pageerror event and perform the loggin there. instead of showing the popup with the error, you can build your own error template which will be shown to the user in those cases...

No this is not what I need. The problem is this: when an exception is thrown i my atlas page inside an update panel a javascript win pops up with an message "Unhadled exception". I don't want that! I want that exception to be catch from a httpHandler that uses the Server.GetLastError() method and shows a message in the ErrorPage.aspx. This is it. How can I do that?

I tried to do this like it is said in previous posts

ScriptManager1.PageError += new Microsoft.Web.UI.PageErrorEventHandler(sm_PageError);

protected void sm_PageError(object sender, Microsoft.Web.UI.PageErrorEventArgs e) {
throw e.Error;

but it doesn't work.

I'm sorry the mistake was in my code. :)

No comments:

Post a Comment