views:

481

answers:

3

Hi,

I have a C# WebService application in which I want to capture all unhandled exceptions thrown from the application.

How can I do this?

+2  A: 

For some reason the Application_Error event does not fire for Web Services (see other question). Mr Jeff Atwood himself has posted some advice on the coding horror blog.

He writes:

* Put a try..catch around every WebService method. These methods tend to be wrappers around other classes, so this isn't quite as bad as it sounds, but it's still not good.
* use a Facade design pattern to derive all objects from parent objects that.. basically do a try..catch on the .Execute method. Uh, thanks but no thanks.
* Write a custom SOAP Extension or HttpModule. This sounds reasonable but.. hard. If it's such a cool, important extension or HttpModule, wouldn't someone have written it already?
codeulike
+1  A: 

One way will be to subscribe to AppDomain.UnhandledException event somewhere in App_Start handler.

Anton Gogolev
A: 

Perhaps a job for an aspect-oriented approach. Some examples;

PostSharp

Spring.Net

Christopherous 5000