PC Review


Reply
Thread Tools Rate Thread

How do I get at windows service exceptions?

 
 
Adam J. Schaff
Guest
Posts: n/a
 
      28th Jan 2004
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.


 
Reply With Quote
 
 
 
 
Adam J. Schaff
Guest
Posts: n/a
 
      28th Jan 2004
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?

"Adam J. Schaff" <(E-Mail Removed)> wrote in message
news:%23hh%(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
 
Adam J. Schaff
Guest
Posts: n/a
 
      28th Jan 2004
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.


"Adam J. Schaff" <(E-Mail Removed)> wrote in message
news:%23hh%(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem catching all exceptions in a windows service Simon Microsoft Dot NET Framework 1 5th Apr 2007 02:43 PM
Problem catching all exceptions in a windows service Simon Microsoft C# .NET 1 5th Apr 2007 02:43 PM
Event log for Windows Service app exceptions -- need better diagnostics SDS Microsoft C# .NET 8 25th Oct 2005 07:19 PM
Q: Timer in windows service not trapping exceptions... Jiho Han Microsoft Dot NET 1 1st Aug 2005 06:45 PM
Handling exceptions in a Windows .Net Service =?Utf-8?B?Sm9obiBNYXJzaA==?= Microsoft Dot NET Framework 4 11th Feb 2005 03:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:53 PM.