How do I get at windows service exceptions?

  • Thread starter Thread starter Adam J. Schaff
  • Start date Start date
A

Adam J. Schaff

For apps I have written in the past, I have always been able to define a
global event handler. Something along the lines of this:

AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf
MyErrHandlerProc

However, I now have a windows service application and when errors occur in
it, I do not receive them. I cannot figure out how to tap into unhandled
exceptions in a windows service. I tried putting the above line of code into
both the Sub Main and the OnStart, and followed it with a "Throw New
Exception" just to see if it would get caught, and it did not. Obviously,
I'm new to windows service and multi-threaded programming.

Can anyone help me out with exception handling? I'd really hate to have to
wrap every procedure of my code with try..catch. It's ugly and I'm not sure
how it would affect performance.

Any help would be deeply appreciated. Thanks.
 
More information:

The handler DOES work if the exception occurs in OnStart. But I have
exception that I know are occurring on other threads that are NOT being
caught by the global exception handler in Sub Main. Anyone know how I can
get at those exceptions?
 
Nevermind. It looks like I was thrown off by reading a post from december
that talked about threads just dying when an unhandled exception occurred
unless they were the main thread. I thought that meant that the appdomain
UnhandledException event would not get fired for them, but testing this with
some threads I created myself shows that it does fire. So the problem I am
facing is probably more mundane:

I am subclassing a class in a 3rd party component. I bet they are handling
exceptions and throwing them away in the base class, so my unhandled
exception handler is never getting them and they do not get logged. Looks
like it's try...catch or nothing. Oh well.
 
Back
Top