5

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

How can I do this?

Cœur
  • 34,719
  • 24
  • 185
  • 251

3 Answers3

2

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?
Community
  • 1
  • 1
codeulike
  • 21,590
  • 28
  • 117
  • 162
1

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

Anton Gogolev
  • 110,157
  • 37
  • 194
  • 282
0

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

PostSharp

Spring.Net

Christoph
  • 4,053
  • 3
  • 23
  • 38