Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
c++ - possible bug in compiler?
As I am new to C++, I thought I ask about this problem before submitting a bug report. While experimenting with the examples in volume 2 of the book Thinking in C++ (http://www.mindview.net) I found that the following program crashes when compiled with Digital Mars (both with version 8.40 and 8.41). #include <exception> using namespace std; void f() throw () { throw 137; } void my_unexpected() { throw; } int main() { set_unexpected(my_unexpected); try { f(); } catch (int i) { } } If 'catch (int)' is used instead of 'catch (int i)', the program doesn't crash. -- Neither does the following example from the book procude correct results (the second catch is not executed). It probably works correctly with older versions of the compiler because all the other examples which do not work with Digital Mars are marked in the book. //: C01:BadException.cpp {-bor} #include <exception> // For std::bad_exception #include <iostream> #include <cstdio> using namespace std; // Exception classes: class A {}; class B {}; // terminate() handler void my_thandler() { cout << "terminate called" << endl; exit(0); } // unexpected() handlers void my_uhandler1() { throw A(); } void my_uhandler2() { throw; } // If we embed this throw statement in f or g, // the compiler detects the violation and reports // an error, so we put it in its own function. void t() { throw B(); } void f() throw(A) { t(); } void g() throw(A, bad_exception) { t(); } int main() { set_terminate(my_thandler); set_unexpected(my_uhandler1); try { f(); } catch(A&) { cout << "caught an A from f" << endl; } set_unexpected(my_uhandler2); try { g(); } catch(bad_exception&) { cout << "caught a bad_exception from g" << endl; } try { f(); } catch(...) { cout << "This will never print" << endl; } } ///:~ Sep 05 2004
|