Fri 5 May 2006
I’ve been using anthem.net (an AJAX framework for .net) recently in a few projects and I’ve run into a problem handling errors on the server, that I haven’t found a good way to handle yet.
Normally in the Application_Error method in Global.asax I either log or send an email every time an error occurs, so that I’m informed immediately if someone experiences a problem.
But if an error occurs on a ajax callback, the Application_Error method is not called!
So I tried overriding the OnError-method on the page, and that went better, at least the method is called. But if I try accessing the eventargs or the Server.GetLastError() they contain no information about the exception.
So in the end I opted to encapsulate each callback method (like the button_click) in a try/catch structure that would activate the errorhandler method I wanted, if an exception was thrown.
But it’s not as good as I wanted, since I have to make sure to do this in every method I use with Anthem, and I really wanted a general solution to this.
Anyone got a better way to solve this?
October 11th, 2006 at 7:57 pm
[…] My blog has moved. You can read the post here: Anthem.net and server error handling […]
February 28th, 2007 at 11:42 pm
David,
What you can do is implementing javascript Anthem_Error function. This function will be invoke if there is an unhandled error occured.
March 1st, 2007 at 1:33 am
ok, thanks for the tip, Hien Khieu.
I will try that out.
March 20th, 2007 at 12:33 am
private void Page_Error(object sender,EventArgs e)
{
Page page = (Page)sender;
Exception ex = page.Server.GetLastError();
if (ex != null && Manager.IsCallBack)
{
//this will get chought by Global.Application_Error method
throw ex;
}
}
October 14th, 2008 at 3:52 pm
anthem errors can only be handled in Anthem_Error(result() method. when ever there is a error, the error i.e result.error is passed as a parameter to this method and it shows the alert box with error message. u capture that error message and log it by redirecting..