[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

C++ exception handling question



I've written a program in C++ using STL for some fairly
tricky simulation work. The program works, but fails
during initialization for some choices of input parameters.
I think the problem is not enough RAM, but I'd like to
confirm that, so I tried enclosing the relevant parts
of int main(...) in a try block to see what exceptions 
I could catch. (I'm using Debian Sarge, and GNU C++ from
Debian repository.)

It seemed like a simple thing to do, but I can't make it
work. Does Debian/GNU C++ support exceptions? Surely, it does
but maybe not. And if it does, where can I find some example
code that throws and catches an exception? What I have done
done follows:

#include "Sys.hh"
#include "nmlib.hh"
#include "rgen2.hh"
#include "nmsim.hh"

int main( int argc, char* argv[] ){
  clog<<"Starting 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;
};

NMsim::NMsim(){};

</end code> 

This program runs normally until it reaches a point in
X.init, where some software object emits the string 'Killed' and then
aborts.  This is about the same place where the program, without try
block, also emits 'Killed' and aborts. 

My code does not have the string 'Killed' in it anywhere, so I suppose
this comes from some place in the C/C++ libraries.  The string "caught
...!!!" never appears in the output, nor does the string " After
catch.".

'#include <exception>' is inside "Sys.hh", but there is no error
message if '#include <exception>' is omitted. The behavior is as if
the compiler silently ignores 'try { ... }' enclosing the operational
code, but that's not true because it gave a useful error message when
I mistakenly included a semicolon between '}' and 'catch'.

Are there special option settings needed in the compiler to enable
exception handling?  Is there an example somewhere on the web of
exception handling that compiles with GCC and runs?

Suggestions?
-- 
Paul E Condon           
pecondon@mesanetworks.net



Reply to: