Boost logo

Boost :

From: Jeffrey D. Paquette (paquette_at_[hidden])
Date: 2000-05-28 07:47:36

You've run afoul of Microsoft translating CPU exceptions into an exception
that cannot be caught except by catch(...) so you really cannot do much with
it, except gracefully exit.

X::~X has run twice because you've destroyed two X's by calling
crash_indirectly() twice. Change:
   catch(...) { }

     std::cerr << "Unknown exception caught"<< std::endl;

and your output becomes:

Unknown exception caught

To trap and convert processor exceptions to C++ objects (or something at
least catchable by type, look into set_se_translator() and be sure to
compile with /EHa.

At last, I've been able to contribute :)

Jeff Paquette
paquette_at_[hidden], paquette_at_[hidden]
-----Original Message-----
From: David Abrahams [mailto:abrahams_at_[hidden]]
Sent: Sunday, May 28, 2000 6:55 AM
To: boost_at_[hidden]
Subject: [boost] solution: Microsoft JIT debugging and catch(...)
The problem: This applies to programs generated by all compilers using
Microsoft-compatible EH when run outside a debugger. I plan to write a
exposition, but I thought I should post this quickly.
#include <iostream>
struct X { ~X() { std::cout << "~X" << std::endl; } };
void crash()
    *((char*)0) = 0;
void crash_indirectly()
    X x;
int main()
   try {
       crash_indirectly(); // You never find out about this crash
   catch(...) { }
   try {
       crash_indirectly(); // When post-mortem debugging starts,
   }                       //  X::~X has already run (twice).
   catch(...) {
The solution:
#include <windows.h>
void structured_exception_translator(
     unsigned int exception_code, EXCEPTION_POINTERS* pExp)
    throw; // magic!
static void (*saved_translator)(unsigned, EXCEPTION_POINTERS*)
  = _set_se_translator(structured_exception_translator);
The line labelled "magic!" above is still a bit of a mystery to me. Without
the debugger appears to re-start the program in the
structured_exception_translator, but the program immediately continues just
in the first example (except that the debugger has been invoked). If anyone
insight into this, I'd appreciate it. I'm sure it's a nitty-gritty Windows
thing, the sort of thing I try to avoid and had to muck about in too much
already to get this far ;). I plan to write a short article for the C++
about this once I get that final detail worked out.
Missing old school friends?  Find them here:

Boost list run by bdawes at, gregod at, cpdaniel at, john at