Question on unhandled exceptions

G

Guest

Hello,

I added this event to handle unhandled exceptions:

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

Recently one occured and added the following to my log file:

UnhandledException, Exception='System.IO.IOException: An unexpected network
error occurred.
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.FileStream.WriteCore(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.FileStream.FlushWrite()
at System.IO.FileStream.Flush()
at System.IO.FileStream.Dispose(Boolean disposing)
at System.IO.FileStream.Finalize()' (Loader.UnhandledException)

I see the stack trace starts at Loader.UnhandledException, which is the
event handler I added. However, all I do there is display an error dialog
and log the ExceptionObject. Does this mean the unhandled error did not
originate from within my app? If that is not the case, why can't I see a
more detailed stack trace, indicating from where the error originated?

Thanks.
 
B

Bruce Wood

Flack said:
Hello,

I added this event to handle unhandled exceptions:

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

Recently one occured and added the following to my log file:

UnhandledException, Exception='System.IO.IOException: An unexpected network
error occurred.
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.FileStream.WriteCore(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.FileStream.FlushWrite()
at System.IO.FileStream.Flush()
at System.IO.FileStream.Dispose(Boolean disposing)
at System.IO.FileStream.Finalize()' (Loader.UnhandledException)

I see the stack trace starts at Loader.UnhandledException, which is the
event handler I added. However, all I do there is display an error dialog
and log the ExceptionObject. Does this mean the unhandled error did not
originate from within my app? If that is not the case, why can't I see a
more detailed stack trace, indicating from where the error originated?

Could you post the code of your UnhandledException method?
 
P

Peter Kirk

Flack said:
UnhandledException, Exception='System.IO.IOException: An unexpected
network
error occurred.
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.FileStream.WriteCore(Byte[] buffer, Int32 offset, Int32
count)
at System.IO.FileStream.FlushWrite()
at System.IO.FileStream.Flush()
at System.IO.FileStream.Dispose(Boolean disposing)
at System.IO.FileStream.Finalize()' (Loader.UnhandledException)

I see the stack trace starts at Loader.UnhandledException, which is the
event handler I added. However, all I do there is display an error dialog
and log the ExceptionObject. Does this mean the unhandled error did not
originate from within my app? If that is not the case, why can't I see a
more detailed stack trace, indicating from where the error originated?

Don't know if it's relevant to your case, but do you "re throw" the
exception, and are you aware of the difference between "throw" and "throw
ex" ?
 
C

Chris Dunaway

Flack said:
Hello,

I added this event to handle unhandled exceptions:

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

Recently one occured and added the following to my log file:

UnhandledException, Exception='System.IO.IOException: An unexpected network
error occurred.
at System.IO.__Error.WinIOError(Int32 errorCode, String str)
at System.IO.FileStream.WriteCore(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.FileStream.FlushWrite()
at System.IO.FileStream.Flush()
at System.IO.FileStream.Dispose(Boolean disposing)
at System.IO.FileStream.Finalize()' (Loader.UnhandledException)

I see the stack trace starts at Loader.UnhandledException, which is the
event handler I added. However, all I do there is display an error dialog
and log the ExceptionObject. Does this mean the unhandled error did not
originate from within my app? If that is not the case, why can't I see a
more detailed stack trace, indicating from where the error originated?

You need to check the InnerException property of that exception. And
then the InnerException property of the InnerException... etc.

Something like this:

StringBuilder sb = new StringBuilder();
while (ex != null)
{
sb.Append(ex.Message + ": " + ex.StackTrace);
ex = ex.InnerException;
}
MessageBox.Show(sb.ToString());
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top