From: Andrew B. <ab...@ee...> - 2001-11-20 00:42:33
|
One addition to this solution (which works, btw, thanks!) re: DLLs. The _catch1 function must be in the same DLL as the try-catch clause, or the C++ exception doesn't make it out of the structured exception handler to the C++ exception handler. Is that a known flaw of C++ exceptions (crossing DLL boundaries) or do I need to add some flags when I compile? Andrew > -----Original Message----- > From: Ruediger Werner [mailto:rue...@la...] >=20 > -----------save this file to something like except.cpp ---------- >=20 > #include <windows.h> > #include <signal.h> >=20 > inline > EXCEPTION_DISPOSITION > _catch1( _EXCEPTION_RECORD* exception_record, > void* err, > _CONTEXT* context, > void* par) > { throw exception_record; } >=20 > int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR > szCmdLine, int iCmdShow) > { > try { > __try1(_catch1) > signal(SIGFPE, SIG_DFL); > int x, y=3D0; > x=3D 5 / y; > return x; > __except1 > } catch(_EXCEPTION_RECORD* seh) { > char buf [100]; > wsprintf (buf, "Structured Exception Error 0x%x",=20 > seh->ExceptionCode); > MessageBox (0, buf, "Structured Exception",=20 > MB_ICONEXCLAMATION | MB_OK); > }; >=20 > try { > __try1(_catch1) > int (*foo)() =3D NULL; > foo(); > __except1 > } catch(_EXCEPTION_RECORD* seh) { > char buf [100]; > wsprintf (buf, "Structured Exception Error 0x%x",=20 > seh->ExceptionCode); > MessageBox (0, buf, "Structured Exception",=20 > MB_ICONEXCLAMATION | MB_OK); > }; >=20 > return 0; > } >=20 >=20 >=20 >=20 >=20 >=20 |