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.

Re: Exception handling by Carl

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



Re: Exception handling by Doug

Doug
Wed Feb 08 11:49:55 CST 2006

On 8 Feb 2006 05:54:22 -0800, "Ronen" <rzilber@sandisk.com> 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.

To add to what Carl said, if your program is "crashing" (due to a bug),
then it's entering a state about which you know nothing. When things that
"cannot happen" do happen, the first rule is, "Do no harm." For example, if
you're a word processor, you shouldn't save all the user's documents by
overwriting his existing good files on disk; instead, before exiting, you
could tell him something went wrong and perhaps offer to write the
documents to new files that he can inspect later.

--
Doug Harrison
Visual C++ MVP