views:

50

answers:

3

Hi all,

I am having some trouble collecting information on an unhandled exception being generated (very rarely) in my code. I have set up an the handler pretty much the standard way.

In the main I have:

AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(ExceptionProcessor);

And the handler function is:

public void ExceptionProcessor(object sender, UnhandledExceptionEventArgs e)
{
    Log(((Exception)e.ExceptionObject).StackTrace);
}

But all I ever get is a single line (not always the same one). Googling revealed that those lines are deep inside the .Net Framework libraries and are meant to be the very last line of the stack trace. So, all of the actually useful information about my code is missing. Does anyone know what could be causing this behaviour?

The line I got most recently says that it can't cast System.Threading.AutoResetEvent to System.Threading._ThreadPoolWaitOrTimerCallback.

Thanks.

A: 

That's quite strange. What is the type of e.ExceptionObject? Is it a custom exception?

My bet is that there's some situation occurring where your actual exception of interest is being caught and then re-thrown somewhere...

Dave Markle
The type is InvalidCastException (default .Net one). And I had the same thought about re-throw :) I've tested it out and re-throwing looses the deep levels while creating the new stack top (at my code level). What I'm see is the opposite, only the deepest level is preserved.
United
A: 

I sometimes use e.tostring() to write the whole exception details into the log. try that..

Suhumar
A: 

Do you log inner exceptions? Each exception has InnerException property which may contain another exception.

Andrew Bezzub