|
From: f.laszlo on 17 Apr 2008 03:43 Hello to all of you, at the moment, I'm despairing! I don't know why my code doesn't work. Have a look: void CMyClass::DoSomething() { try { DoItNow(); } catch(...) { std::cout << "Exception caught!\n"; } } void CMyClass::DoItNow() { throw 5; } I compiled this code with -fexceptions and when I try to run it, after the call of DoItNow(), the programm aborts with SIGABRT. WHY??????????? -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Martin York on 17 Apr 2008 10:35 On Apr 17, 11:43 am, "f.las...(a)pilz.de" <f.las...(a)pilz.de> wrote: > Hello to all of you, > > at the moment, I'm despairing! I don't know why my code doesn't work. > Have a look: > > void CMyClass::DoSomething() > { > try > { > DoItNow(); > } > catch(...) > { > std::cout << "Exception caught!\n"; > } > > } > > void CMyClass::DoItNow() > { > throw 5; > > } > > I compiled this code with -fexceptions and when I try to run it, after > the call of DoItNow(), the programm aborts with SIGABRT. > > WHY??????????? > > -- > [ Seehttp://www.gotw.ca/resources/clcm.htmfor info about ] > [ comp.lang.c++.moderated. First time posters: Do this! ] Works Fine for me: This is what I compiled: $ cat X.cpp #include <iostream> struct CMyClass { void DoSomething(); void DoItNow(); }; void CMyClass::DoSomething() { try { DoItNow(); } catch(...) { std::cout << "Exception caught!\n"; } } void CMyClass::DoItNow() { throw 5; } int main() { CMyClass x; x.DoSomething(); } This is my results: $ g++ -fexceptions X.cpp $ ./a.exe Exception caught! -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: f.laszlo on 17 Apr 2008 21:13 Hi! I found my mistake... ;-) It was just a stupid error: DoItNow has been called earlier in another function with no try/catch block: so the thrown exception has never been caught..... Thanks anyway! Frank -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Chris Uzdavinis on 17 Apr 2008 21:13 On Apr 17, 2:43 pm, "f.las...(a)pilz.de" <f.las...(a)pilz.de> wrote: > at the moment, I'm despairing! I don't know why my code doesn't work. > Have a look: [...] > I compiled this code with -fexceptions and when I try to run it, after > the call of DoItNow(), the programm aborts with SIGABRT. > > WHY??????????? Based on what you have shown, I'd have to say the problem is in the code that you decided not to post. Please show a truly minimal program that actually compiles and demonstrates the problem, and perhaps you will receive better help. -- Chris -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
|
Pages: 1 Prev: generation of called member functions Next: auto_ptr for array of built-ins |