The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

catching unhandled exceptions

"Working on CityDesk, Part One" mentions that "Micheal [Pryor] wrote some very spiffy code that catches any unhandled exception".

How does one go about doing that? Any pointers would be appreciated.
coder Send private email
Monday, December 18, 2006
 
 
Probably, "logging unhandled exceptions" was the appropriate term.
This is usually done when you have designed your application to handle all exceptions and errors at a central location.
Vineet Reynolds Send private email
Monday, December 18, 2006
 
 
In any modern environment this should be trivial. In .NET, look at the Application.ThreadException event. This is thread level, not process level but covers most things.
Adrian
Monday, December 18, 2006
 
 
SetUnhandledExceptionFilter will do the trick for structured exceptions (access violation and so forth).

You get EBP and ESP in the input, so you can do a stack walk (then use the thread information block to determine the stack limits), and use the dbghelp library to extract the symbols. Then save the result as text to a file.

Alternatively, you could use the minidump facility -- I've never bothered with this myself, as the results aren't text, but depending on your situation this could well be more suitable. There are some codeproject articles about this.
Tom_
Monday, December 18, 2006
 
 
"(then use the thread information"... should be "(use the thread information"...
Tom_
Monday, December 18, 2006
 
 
Stack Trace Exceptions in Win32  [Example code, and technical details.]
http://www.eptacom.net/pubblicazioni/pub_eng/except.html


Also, check out the DbgHelp library, for platform support. (I assume but haven't checked that this does Win64 as well.)


Or, perhaps, sign up for access to the debugging logs that get sent to Microsoft when applications crash, and let the OS do the heavy lifting regardless of platform.

Monday, December 18, 2006
 
 
Having a top-level uber exception handler will do the trick, assume all of your code generates exceptions in an uniformed manner.

For example, if you have used C code that returns result code instead of exceptions, than you should look at wrapping the result code with an exception object so it can be handled appropriately.  The same goes if you are invoking any external processes or other external libraries that handles errors differently than your application code.
Yin-So Chen Send private email
Monday, December 18, 2006
 
 
I added this into one of my C++ apps. See my article http://blog.surfulater.com/2005/07/19/surfulater-v182-b00-released/  It has proved very useful.

I use XCrashHandler which you will find at www.codeproject.com
Neville Franks Send private email
Monday, December 18, 2006
 
 
Thank you all for your replies!
coder
Tuesday, December 19, 2006
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz