Windows Service

  • Thread starter Thread starter Peter Larsen [CPH]
  • Start date Start date
P

Peter Larsen [CPH]

Hi,

Is there a way to catch all unhandled exceptions in a windows service ?

Thank you in advance.
BR
Peter
 
-forgot to mention that i use dot net 3,5.

/Peter
You can use AppDomain.UnhandledException
(http://msdn.microsoft.com/en-us/library/system.appdomain.unhandledexception.aspx)
to provide some behavior whenever an exception is not caught somewhere.

Note however that this is not the same as "catching" the event. The
exception IS considered unhandled, it WILL crash your service, this just
gives you a chance to do something before your service dies (like log
current state).

-Adam
 
Is there a way to catch all unhandled exceptions in a windows service ?

What functionality are you looking for that the obvious try catch
does not provide?

Arne
 
Thanks for your replies - I appreciate your help.

The problem is not unhandled exceptions in general, but how to handle
exceptions without crashing the service, like Adam is writing about.
Sometimes you don't care about how a thread was ended, but in a service
application, it is necessary to handle all exceptions - I now understand
this.

/Peter
 
Back
Top