views:

1601

answers:

3

I'm using the [System.Web.Script.Services.ScriptService] tag to use web services callable from client side javascript. What I need is a way of globally logging any unhandled exceptions in those methods. On the client side, I get the error callback and can proceed from there, but I need a server-side catch to log the exception.

The guy at this url: http://ayende.com/Blog/archive/2008/01/06/ASP.Net-Ajax-Error-Handling-and-WTF.aspx

suggests that this can't be done.

Is that accurate? Do I seriously have to go to every single webmethod in the entire system and try/catch the method as a whole.

A: 

In ASP.Net it is possible to catch all run handled exceptions using a global error handler although the blog post suggest this would not work but you could experiment with this approach trying to rethrow the error in some way?

Another idea would be to look at the open source elmah (Error Logging Modules and Handlers) for ASP.Net that might help or someone in that community may have an idea.

John
Yeah, I'm not sure you really understood the problem. The exception *is* caught by the ASP.NET script service code -- caught before I have a chance to catch it. So the global error handler doesn't work. The framework sends an error client-side so I can display a message, but there's no server hook
Clyde
However, the elmah link is interesting...I will be sure to check that out
Clyde
I'd second ELMAH. I use that for exactly this purpose myself.
Dave Ward
+3  A: 
Daniel Richardson
Although I'm not following through with this on my current project, this probably is the only way to reliably catch all these errors.
Clyde
+1  A: 

I know this doesn't answer the question per-say, but I went on my own quest a while back to find this out and would up empty handed. Ended up wrapping each web service call in a try/catch, and the catch calls our error logger. Sucks, but it works.

Nicholas H