File: exctest3.cc

package info (click to toggle)
clhep 2.1.4.1%2Bdfsg-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,012 kB
  • sloc: cpp: 50,094; sh: 6,694; makefile: 2,694; perl: 28
file content (57 lines) | stat: -rwxr-xr-x 1,234 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Test program to check out the environment exception-handling

#include <iostream>
using std::cerr;
using std::endl;


class Exception  {
public:
  Exception( const char [] )  {}
  virtual ~Exception() {}
  virtual void f() const { cerr << "Exception::f()" << endl; }
};


class Oops : public Exception  {
public:
  Oops( const char s[] ) : Exception( s )  {}
  virtual ~Oops() {}
  virtual void f() const { cerr << "Oops::f()" << endl; }
};


int main()  {

  try  {
    cerr << "Starting main() ..." << endl;
    cerr << "About to:  throw( Oops(\"Ouch\") )" << endl;

    try { throw Oops("Ouch"); }
    catch ( const Exception & x )  {
      x.f();
      throw;
    }
    catch ( ... )  {
      cerr << "Caught unknown!" << endl;
      throw;
    }

    // Unreachable statement (we certainly hope!):
    cerr << "The following ought to produce a compilation warning \n"
         << "Got past:  throw( Oops(\"Ouch\") ) -- not good!" << endl;
  }
  catch ( const Oops & egad )  {
    cerr << "Caught:  Oops" << endl;
  }
  catch ( const Exception & egad )  {
    cerr << "Caught:  Exception" << endl;
  }
  catch ( ... )  {
    cerr << "Caught:  don't know what" << endl;
  }

  cerr << "Done." << endl;
  return 0;

}  // main()