Console application failing to catch errors

  • Thread starter Thread starter Mantorok
  • Start date Start date
M

Mantorok

Hi all

I have a console application that runs every night via a scheduled task,
there is a try-catch block in my Main class, whenever an error is caught it
is written to a log file and then emailed to several people. The
application is run using a domain service account, if the program is
successful it emails this result fine.

The problem is, the catch doesn't seem to perform correctly if the program
fails, all I end up with is an entry in the event-log with almost
meaningless error details.

My only thought was that maybe these errors are occurring in my
multi-threaded calls (there are a few).

Is there any reason why the catch would fail? I'm running out of ideas.

Thanks
Kev
 
Hi Kev,

Perhaps you don't have permission on the log file and the application is
bombing out before the sending mail portion of the program is sent.
--
Regards
Lee Alexander
www.feedghost.com
An RSS Reader for Vista & XP
Synchronize, search, tag and share.
 
My only thought was that maybe these errors are occurring in my
multi-threaded calls (there are a few).

Quite possibly. If you're doing stuff in worker threads you need to
have an exception handler on each worker thread that either logs the
error or communicates the error back to the main thread. If a worker
thread fails due to an exception it won't communicate anything to the
main thread by default, it will simply shut down.
 
Chris Nahr said:
Quite possibly. If you're doing stuff in worker threads you need to
have an exception handler on each worker thread that either logs the
error or communicates the error back to the main thread. If a worker
thread fails due to an exception it won't communicate anything to the
main thread by default, it will simply shut down.

I'm pretty sure that's the problem, how do you catch exceptions from
additional threads?

Thanks
Kev
 
Chris Nahr said:
Quite possibly. If you're doing stuff in worker threads you need to
have an exception handler on each worker thread that either logs the
error or communicates the error back to the main thread. If a worker
thread fails due to an exception it won't communicate anything to the
main thread by default, it will simply shut down.

It is that, I'm now handling my exceptions inside the appropriate threads
and it's working now.

Thanks
Kev
 
I'm pretty sure that's the problem, how do you catch exceptions from
additional threads?

In the same way as usual, just make sure the exception handler runs on
the thread in question...
 
Back
Top