From: Olivier M. <om...@ti...> - 2004-03-01 10:11:08
|
On 1/03/2004 9:54 GMT+1, Dimitry Sibiryakov wrote: > I might do something wrong in my tests, but I was unable to make > gcc 3.2.3 (mingw) to handle C++ exception, thrown from inside > UnhandledExceptionFilter. This thrown exception missed all catch() > blocks and went straight to unexpected exception handler which by > default abort the process. I confirm issues with MinGW g++, issues that were known as I remember previous discussions here. The test code (below, after my sig) compiles and run okay with BCC32 5.6.4 and prints: c:\Dev\Exception>bcc32 except.cpp c:\Dev\Exception>except Main start. Engine start. In globalUnhandledExceptionFilter In handleException OS signal detected (c0000005 at address 401d76) Engine stop. Main stop. With MinGW g++.exe 3.2.3 (20030504-1), it compiles as flawlessly but prints: $ g++ except.cpp $ a Main start. Engine start. In globalUnhandledExceptionFilter This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. -- Best Regards, Olivier Mascia // except.cpp -*- C++; tab-size:4 -*- #include <windows.h> #include <exception> #include <iostream> #include <iomanip> #include <typeinfo> using namespace std; class os_signal : public exception { public: DWORD mCode; VOID* mAddress; os_signal(DWORD code, VOID* address) : mCode(code), mAddress(address) { } }; LONG __stdcall globalUnhandledExceptionFilter(EXCEPTION_POINTERS* pei) { EXCEPTION_RECORD* per = pei->ExceptionRecord; cout<< "In globalUnhandledExceptionFilter"<< endl; throw os_signal(per->ExceptionCode, per->ExceptionAddress); //return EXCEPTION_CONTINUE_EXECUTION; } void handleException(const exception& ex) { cout<< "In handleException"<< endl; const type_info& ex_type = typeid(ex); if (ex_type == typeid(os_signal)) { const os_signal* pex = dynamic_cast<const os_signal*>(&ex); cout<< "OS signal detected ("; cout<< hex<< pex->mCode<< " at address "<< pex->mAddress<< ")"<< endl; } else if (ex_type == typeid(bad_alloc)) { cout<< "bad_alloc detected"<< endl; } else { cout<< "Other std::exception"<< endl; } } void engine(void) { cout<< "Engine start."<< endl; try { char* p = 0; *p = 'e'; cout<< "Did not failed!"<< endl; } catch (exception& e) { handleException(e); } catch (...) { cout<< "Unmapped exception occured. This demo code miserably failed."<< endl; } cout<< "Engine stop."<< endl; } int main() { cout<< "Main start."<< endl; SetUnhandledExceptionFilter(globalUnhandledExceptionFilter); engine(); cout<< "Main stop."<< endl; return 0; } // Eof |