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++ - throwing an exception in a new expression
Here is a test-case (I get an "abnormal program termination" message): #include <stdio.h> struct A { }; struct B { B() { throw A(); } }; int main() { try { B *b = new B(); //B b; // this one works } catch (const A &a) { printf("caught A\n"); } return 0; } BTW, the problem also occurs when the exception isn't thrown directly in the constructor, but somewhere in the new expression: #include <stdio.h> struct A { }; struct B { B(int i) { } }; int f() { throw A(); return 0; } int main() { try { B *b = new B(f()); //B b(f()); } catch (const A &a) { printf("caught A\n"); } return 0; } bye, Christof -- http://cmeerw.org JID: cmeerw jabber.at mailto cmeerw at web.de ...and what have you contributed to the Net? Nov 09 2002
In article <aql8j0$hol$1 digitaldaemon.com>, Walter says...Got it, thanks. -Walter Nov 13 2002
Well, Ok, it turned out to be user error again. This time an access violation reached by the d'tor of the template. I was assigning a null object to a reference. Similiar to: void f(const Object& check) { Object* ptr = 0; Object& ref = *ptr; if (ref == check) // do something.. } So stack unwind caught it, and generated an abnormal program termination. Richard Nov 13 2002
In article <aql8j0$hol$1 digitaldaemon.com>, Walter says...Got it, thanks. -Walter Nov 14 2002
It'll take a while. I'm pretty buried at the moment. -Walter "Richard" <fractal clark.net> wrote in message news:ar092i$1as0$1 digitaldaemon.com...In article <aql8j0$hol$1 digitaldaemon.com>, Walter says...Got it, thanks. -Walter Nov 14 2002
|