Default .NET exception handler
So the other day my C# applic开发者_Python百科ation crashed. Usually, with a .NET application, if you have an unhandled exception you get a nice error message with a stack trace.
However, this time, I got a different dialog that just told me there was an error and offered to attach a Debugger, but there was no stack trace in the dialog and the machine it was running on had no debugger installed.
What gives? Why don't I see the default .NET exception handler?
Many, many things can cause this to happen:
- Crashes in unmanaged code (i.e. access violations, bad GDI calls, closed handles, etc.);
- Unhandled exceptions on background threads;
- Unhandled exceptions in certain message handlers (i.e.
OnPaint
); - Fatal exceptions such as
OutOfMemoryException
,StackOverflowException
,BadImageFormatException
, and so on - which could prevent the global exception handler from ever running; - Unhandled exceptions occurring during app initialization or shutdown;
- Hardware failures - bad memory/disk sectors, etc.
- ...and many more.
Really the only way to be sure is to determine steps that will reproduce the error and use a tool like WinDbg to actually debug the part that's crashing.
You probably crashed in unmanaged code that is in use either directly or indirectly by your application.
And if you access protected memory in unmanaged code, that's it. You're not going to manage the exception and bubble/propagate anything. Your process will crash the old fashioned way and you'll need old-fashioned tools and techniques to find the error.
精彩评论