Carl
Wed Feb 08 08:55:19 CST 2006
Ronen wrote:
> Hi all experts,
>
> I have an application that crush from time to time .
> The application is:
> vc++ mfc based.
> Multithreads
> With gui.
>
>
> The objective is to catch the exception before the applications
> crashes so I could close the application manually.
OK, so catch the exception. But be aware that your application is in an
unknown state when the exception is raised, so you may not be able to even
stop the application normally at that point.
use try/catch to catch C++ exceptions (including MFC).
use __try/__finally to catch platform exceptions (e.g. access violation).
You can use _set_se_translator() to convert platform exceptions into C++
exceptions. Be aware that you must compile with /EHa, and you must invoke
_set_se_translator in each and every thread (that you control).
See the following links for more:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_core_exception_handling_topics_.28.c.2b2b29.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_core_mixing_c_and_c.2b2b_.exceptions.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/_core_Exception_Handling_Topics_.28.MFC.29.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt__set_se_translator.asp
Finally, when you get an exception that's going to cause you to terminate
the application, you might want to write out a mini-dump file. This file
can be loaded into a debugger to examine the program state at the point of
the dump.
http://msdn.microsoft.com/msdnmag/issues/05/07/Debugging/default.aspx
-cd