Re: exceptions in gnu c++
Hi Paul, On Sun, 2006-11-05 at 18:34 -0700, Paul E Condon wrote: On Sun, Nov 05, 2006 at 10:51:15PM +0100, Christian Holm Christensen wrote: Hi Paul, ... On Sun, 2006-11-05 at 14:29 -0700, Paul E Condon wrote: ... I have a new version of my program and I have switched to g++-3.4 The newer version addresses issues about the actual name of the exception: #include Sys.hh #include nmlib.hh #include rgen2.hh #include nmsim.hh int main( int argc, char* argv[] ){ clogStarting nmmain...endl; try { NMsim X; // instantiate the simulation object X.nminit( argc, argv ); // read in parameters and generate starting conditions X.nmcore( ); // do a simulation run } catch (...) { clog caught ...!!! endl; } clog After catch.endl; return 0; }; /end The output still shows no sign that the catch block is entered. Still the same 'Killed' word from somewhere. Did you try to use GDB to figure out what's going on? If not, give that a whirl. Also, It's kinda hard to see where your code fails when we only can see the few lines above. Perhaps you should post your code on some web-site so that someone else can download it, compile it, and run it, to get a better idea of what might be wrong. Should I be able to put essentially all of a program inside a try block like I'm doing here? Yep. It is hard to believe that this is an undiscovered bug in gnu c++. What might be missing from my code? Don't know - we can't see most of the code! I've never done try/catch before so don't hesitate to suggest the 'obvious'. What you have above is fine. However, the error is probably at some deeper level - say somewhere in the NMsim class. Sorry, with out more information, it will be hard to give you any hints, directions, or help. Yours, -- ___ | Christian Holm Christensen |_| | - | | Address: Sankt Hansgade 23, 1. th. Phone: (+45) 35 35 96 91 _| DK-2200 Copenhagen N Cell: (+45) 24 61 85 91 _|DenmarkOffice: (+45) 353 25 404 | Email: [EMAIL PROTECTED] Web:www.nbi.dk/~cholm | | -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: exceptions in gnu c++
Paul E Condon [EMAIL PROTECTED] writes: row: 21100 128Killed Killed almost certainly indicates that something (likely the kernel) sent your application a SIGKILL signal, which instantly terminates your application, with the message itself coming from your shell. (Running your program under strace should confirm this.) Moreover, Unix signals are generally a separate matter from exceptions, and converting one to the other is easier said than done. -- Aaron M. Ucko, KB1CJC (amu at alum.mit.edu, ucko at debian.org) Finger [EMAIL PROTECTED] (NOT a valid e-mail address) for more info. -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: exceptions in gnu c++
Paul, Run top -d 1 from another terminial before starting your program. It should show clearly the memory usage climbing if your code has a leak. Hit shift-M to sort by memory usage. If this is indeed the case I suggest that you recompile with -g and then run your program under valgrind to find the source of your memory leak. Luck, -Brett. -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: exceptions in gnu c++
On Mon, Nov 06, 2006 at 10:56:38AM +0100, Christian Holm Christensen wrote: Hi Paul, On Sun, 2006-11-05 at 18:34 -0700, Paul E Condon wrote: On Sun, Nov 05, 2006 at 10:51:15PM +0100, Christian Holm Christensen wrote: Hi Paul, ... On Sun, 2006-11-05 at 14:29 -0700, Paul E Condon wrote: ... I have a new version of my program and I have switched to g++-3.4 The newer version addresses issues about the actual name of the exception: #include Sys.hh #include nmlib.hh #include rgen2.hh #include nmsim.hh int main( int argc, char* argv[] ){ clogStarting nmmain...endl; try { NMsim X; // instantiate the simulation object X.nminit( argc, argv ); // read in parameters and generate starting conditions X.nmcore( ); // do a simulation run } catch (...) { clog caught ...!!! endl; } clog After catch.endl; return 0; }; /end The output still shows no sign that the catch block is entered. Still the same 'Killed' word from somewhere. Did you try to use GDB to figure out what's going on? If not, give that a whirl. Also, It's kinda hard to see where your code fails when we only can see the few lines above. Perhaps you should post your code on some web-site so that someone else can download it, compile it, and run it, to get a better idea of what might be wrong. Should I be able to put essentially all of a program inside a try block like I'm doing here? Yep. It is hard to believe that this is an undiscovered bug in gnu c++. What might be missing from my code? Don't know - we can't see most of the code! I've never done try/catch before so don't hesitate to suggest the 'obvious'. What you have above is fine. However, the error is probably at some deeper level - say somewhere in the NMsim class. Sorry, with out more information, it will be hard to give you any hints, directions, or help. From another list I've received the suggestion that 'Killed' is coming from the OS, which issued it while processing a SIGHUP. This sounds plausible to me. For some reason, my program got itself into a state in which it couldn't process the throwing of an exception, and couldn't do anything else, and it got killed by the OS (Linux). Further investigation will have to wait for a few days. I'm a precinct election judge and need to be ready for work all day tomorrow. And then a day or so to recover. Thanks for your help. -- Paul E Condon [EMAIL PROTECTED] -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: exceptions in gnu c++
On Mon, Nov 06, 2006 at 12:01:26PM -0500, Brett Viren wrote: Paul, Run top -d 1 from another terminial before starting your program. It should show clearly the memory usage climbing if your code has a leak. Hit shift-M to sort by memory usage. If this is indeed the case I suggest that you recompile with -g and then run your program under valgrind to find the source of your memory leak. I think I understand what's happening. What to do about it is another matter. For now, I intend to avoid attempting to run with parameter values that result in crash, while I attend to other matters. All responses were valuable in un-muddling my thinking. Thanks. -- Paul E Condon [EMAIL PROTECTED] -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
exceptions in gnu c++
I've written a simulation program in c++. It works for small problems of its class, but fails during initialization on large problems. I suspect I need more RAM, but would like confirmation, so ... I changed the main program to include a everything in a try block with a catch block, etc. But it still dies in the same way. Where can I find an example of exception handling code that works with gcc 3.3? My code is: using namespace std; #include Sys.hh #include nmlib.hh #include rgen2.hh #include nmsim.hh int main( int argc, char* argv[] ){ coutStarting nmmain...endl; try { NMsim X; // instantiate the simulation object X.nminit( argc, argv ); // read in parameters and generate starting conditions X.nmcore( ); // do a simulation run } catch (const exception caught) { cout caught exception: caught.what() !!! endl; } cout After catch.endl; return 0; }; NMsim::NMsim(){}; /end The output is: gq:/da4/wdl/H$ nmmain --steps 200 --stpsiz 200 --kernparm 1024. vaa.a Starting nmmain... init set to 255 done with tbl/abn/sid preparation start dispersal calc with rx=5418 row: 21100 128Killed gq:/da4/wdl/H$ /end Notice the 'debug' statements being sent to cout. 'Killed' comes from some gcc library, not from my code, especially not from my catch block. The detailed syntax that I'm attempting to use is taken from Josuttis, p. 15. He footnotes it with a caveat that it is not in the Standard, only proposed. Looks like something in the c++ library is catching whatever is being thrown (if anything) and killing nmmain before control gets to my catch and/or return stmnts. suggestions? (like maybe a more appropriate list to ask?) -- Paul E Condon [EMAIL PROTECTED] -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
Re: exceptions in gnu c++
Hi Paul, On Sun, 2006-11-05 at 14:29 -0700, Paul E Condon wrote: I've written a simulation program in c++. It works for small problems of its class, but fails during initialization on large problems. I suspect I need more RAM, but would like confirmation, so ... I changed the main program to include a everything in a try block with a catch block, etc. But it still dies in the same way. Where can I find an example of exception handling code that works with gcc 3.3? Can you switch to 3.4+? 3.3 is buggy. My code is: using namespace std; #include Sys.hh #include nmlib.hh #include rgen2.hh #include nmsim.hh int main( int argc, char* argv[] ){ coutStarting nmmain...endl; try { NMsim X; // instantiate the simulation object X.nminit( argc, argv ); // read in parameters and generate starting conditions X.nmcore( ); // do a simulation run } catch (const exception caught) { You should catch a reference to an exception object - not a real object. The reason is, that you'd only get a copy, and that may not be done right. So you should have } catch (const exception caught) { cout caught exception: caught.what() !!! endl; Perhaps you should return a non-null value here. Also, perhaps you want to dump error messages to `std::cerr' and debug messages to `std::clog'. } cout After catch.endl; return 0; }; NMsim::NMsim(){}; /end The output is: gq:/da4/wdl/H$ nmmain --steps 200 --stpsiz 200 --kernparm 1024. vaa.a Starting nmmain... init set to 255 done with tbl/abn/sid preparation start dispersal calc with rx=5418 row: 21100 128Killed gq:/da4/wdl/H$ /end Notice the 'debug' statements being sent to cout. 'Killed' comes from some gcc library, not from my code, especially not from my catch block. I think the reference will fix it. If not, try running the program through GDB and set a break-point in `std::terminate' (the function called for un-caught exceptions) and then back-trace. The detailed syntax that I'm attempting to use is taken from Josuttis, p. 15. Perhaps a URL would be good? He footnotes it with a caveat that it is not in the Standard, only proposed. Looks like something in the c++ library is catching whatever is being thrown (if anything) and killing nmmain before control gets to my catch and/or return stmnts. Ye, that would be `std::terminate'. However, the caveat is probably no longer valid. The `std::terminate' function will be called if your catch blocks does not match the exception thrown. The C++ library only throws exceptions that inherit from std::exception, so that should be caught. However, if some code throws a std::string or something, that will not be caught by your catch block. If you want to catch all exceptions, no matter the type, you could append _another_ catch block like catch (...) { std::cerr Caught unknown exception std::endl; } suggestions? (like maybe a more appropriate list to ask?) A list dedicated to C++ questions would be an obvious choice :-) Yours, -- ___ | Christian Holm Christensen |_| | - | | Address: Sankt Hansgade 23, 1. th. Phone: (+45) 35 35 96 91 _| DK-2200 Copenhagen N Cell: (+45) 24 61 85 91 _|DenmarkOffice: (+45) 353 25 404 | Email: [EMAIL PROTECTED] Web:www.nbi.dk/~cholm | | -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]