c++ - throwing an exception in a new expression
- Christof Meerwald (59/59) Nov 09 2002 Here is a test-case (I get an "abnormal program termination" message):
- Walter (1/1) Nov 10 2002 Got it, thanks. -Walter
- Richard (9/10) Nov 13 2002 mmm.. I get something similiar in instantiation a template object. I got...
- Richard (12/12) Nov 13 2002 Well,
- Richard (10/11) Nov 14 2002 After I fixed my access violation, I found I was using new operator in a
- Walter (6/18) Nov 14 2002 It'll take a while. I'm pretty buried at the moment. -Walter
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. -Waltermmm.. I get something similiar in instantiation a template object. I got a template c'tor that like: mytemp() throw (Exception) And if I put the instantiation of the object inside try block and then later throw any exception, I can't catch the exception and get A.B. Normal. I was not able to isolate the problem, and am not using new operator. If I move the instantiation out of the try block, I get a catch on the Exception. Richard
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. -WalterAfter I fixed my access violation, I found I was using new operator in a critical template and throwing exceptions during the construction chain. There's no useful way to create these objects on the stack or as static. Sorry to sound pushy, but can you give some indication about when a fix for abend when throwing an exeption in a new expression might be available. Feel free to say its going to take a while, and I'll hack the exisiting startup code to handle it. Since its somewhat onerous, and the result temporary, I figured I'd ask before doing it. Richard
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...There'sGot it, thanks. -WalterAfter I fixed my access violation, I found I was using new operator in a critical template and throwing exceptions during the construction chain.no useful way to create these objects on the stack or as static. Sorry to sound pushy, but can you give some indication about when a fixforabend when throwing an exeption in a new expression might be available. Feel free to say its going to take a while, and I'll hack the exisitingstartupcode to handle it. Since its somewhat onerous, and the result temporary, I figured I'd ask before doing it. Richard
Nov 14 2002