CLHEP 2.0.4.7 Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

exctest2.cc

Go to the documentation of this file.
00001 // Test program to check out environment's exception-handling
00002 
00003 #include <iostream>
00004 using std::cerr;
00005 using std::endl;
00006 
00007 
00008 class Exception  {
00009 public:
00010   Exception( const char [] )  {}
00011 };
00012 
00013 
00014 class Oops : public Exception  {
00015 public:
00016   Oops( const char s[] ) : Exception( s )  {}
00017 };
00018 
00019 
00020 int main()  {
00021 
00022   try  {
00023     cerr << "Starting main() ..." << endl;
00024 
00025     cerr << "About to:  throw( Oops(\"Ouch\") )" << endl;
00026     const Exception & o = Oops("Ouch");
00027     throw o;
00028     cerr << "The following ought to produce a compilation warning \n"
00029          << "Got past:  throw( Oops(\"Ouch\") ) -- not good!" << endl;
00030   }
00031   catch ( const Oops & egad )  {
00032     cerr << "Caught:  Oops" << endl;
00033   }
00034   catch ( const Exception & egad )  {
00035     cerr << "Caught:  Exception" << endl;
00036   }
00037   catch ( ... )  {
00038     cerr << "Caught:  don't know what" << endl;
00039   }
00040 
00041   cerr << "Done." << endl;
00042   return 0;
00043 
00044 }  // main()

Generated on Thu Jul 1 22:02:30 2010 for CLHEP by  doxygen 1.4.7