> I was thinking there should be a way to get control if the program was
> about to crash, then write the file. I don't see exactly how to do it,
> though. I found the set_terminate() function, but I'm not sure that
> does exactly what I want.
>
> It claims that each thread needs to set its own set_terminate(). I
> understand that as meaning that if a worker thread crashes, and I only
> did a set_terminate() in the UI thread, that it wouldn't get called.
> Is that true?

How about SetUnhandledExceptionFilter( )?  It doesn't need to be set per
thread, but it's executed in the context of the thread which has raised the
exception (naturally.)

> Also, as a more fundamental question (exposing my ignorance even
> more!), is everything that makes a program crash an exception that
> gets caught by the routine that calls the terminate function, or does
> this only work when something calls "throw"?

Yes, under Win32, everything that makes an app crack is a Structured Win32
Exception.  It could be an access violation, division by zero, stack
overflow, or maybe an uncaught C++ exception (C++ exceptions are implemented
in terms of Win32 Structured Exceptions by MSVC.)  Of course, don't confuse
a crash with a hang (when the program falls into an infinite loop) and a
deadlock (caused by lack of correct synchronization between threads.) - but
remember that both of them as well can also turn into unhandled exceptions
(a stack overflow for the former, and an access violation for the latter.)

Actually, and unhandled exception is one caught by the OS in the OS core
libraries in a caller of the program's main/WinMain function.  Thus, if
there's a program structured along the lines of:

 int main()
 {
  __try
  {
   // program's code
  }
  __except( EXCEPTION_EXECUTE_HANDLER )
  {
   // handle all exceptions
  }
 }

Then there won't be any unhandled exceptions under any circumstances (except
for when the code inside the __except block raises an exception.

-------------
Ehsan Akhgari

Farda Technology (http://www.farda-tech.com/)

List Owner: [EMAIL PROTECTED]

[ Email: [EMAIL PROTECTED] ]
[ WWW: http://www.beginthread.com/Ehsan ]

They have something of which they are proud. What do they call it, that
which makes them proud? Culture, they call it; it distinguishes them from
the goatherds.
-Thus Spoke Zarathustra, F. W. Nietzsche





Reply via email to