CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

exctest3.cc

Go to the documentation of this file.
00001 // Test program to check out the environment 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   virtual ~Exception() {}
00012   virtual void f() const { cerr << "Exception::f()" << endl; }
00013 };
00014 
00015 
00016 class Oops : public Exception  {
00017 public:
00018   Oops( const char s[] ) : Exception( s )  {}
00019   virtual ~Oops() {}
00020   virtual void f() const { cerr << "Oops::f()" << endl; }
00021 };
00022 
00023 
00024 int main()  {
00025 
00026   try  {
00027     cerr << "Starting main() ..." << endl;
00028     cerr << "About to:  throw( Oops(\"Ouch\") )" << endl;
00029 
00030     try { throw Oops("Ouch"); }
00031     catch ( const Exception & x )  {
00032       x.f();
00033       throw;
00034     }
00035     catch ( ... )  {
00036       cerr << "Caught unknown!" << endl;
00037       throw;
00038     }
00039 
00040     // Unreachable statement (we certainly hope!):
00041     cerr << "The following ought to produce a compilation warning \n"
00042          << "Got past:  throw( Oops(\"Ouch\") ) -- not good!" << endl;
00043   }
00044   catch ( const Oops & egad )  {
00045     cerr << "Caught:  Oops" << endl;
00046   }
00047   catch ( const Exception & egad )  {
00048     cerr << "Caught:  Exception" << endl;
00049   }
00050   catch ( ... )  {
00051     cerr << "Caught:  don't know what" << endl;
00052   }
00053 
00054   cerr << "Done." << endl;
00055   return 0;
00056 
00057 }  // main()

Generated on 15 Nov 2012 for CLHEP by  doxygen 1.4.7