CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
exctest3.cc
Go to the documentation of this file.
1// Test program to check out the environment exception-handling
2
3#include <iostream>
4using std::cerr;
5using std::endl;
6
7
8class Exception {
9public:
10 Exception( const char [] ) {}
11 virtual ~Exception() {}
12 virtual void f() const { cerr << "Exception::f()" << endl; }
13};
14
15
16class Oops : public Exception {
17public:
18 Oops( const char s[] ) : Exception( s ) {}
19 virtual ~Oops() {}
20 virtual void f() const { cerr << "Oops::f()" << endl; }
21};
22
23
24int main() {
25
26 try {
27 cerr << "Starting main() ..." << endl;
28 cerr << "About to: throw( Oops(\"Ouch\") )" << endl;
29
30 try { throw Oops("Ouch"); }
31 catch ( const Exception & x ) {
32 x.f();
33 throw;
34 }
35 catch ( ... ) {
36 cerr << "Caught unknown!" << endl;
37 throw;
38 }
39
40 // Unreachable statement (we certainly hope!):
41 cerr << "The following ought to produce a compilation warning \n"
42 << "Got past: throw( Oops(\"Ouch\") ) -- not good!" << endl;
43 }
44 catch ( const Oops & egad ) {
45 cerr << "Caught: Oops" << endl;
46 }
47 catch ( const Exception & egad ) {
48 cerr << "Caught: Exception" << endl;
49 }
50 catch ( ... ) {
51 cerr << "Caught: don't know what" << endl;
52 }
53
54 cerr << "Done." << endl;
55 return 0;
56
57} // main()
Exception(const char[])
Definition: exctest3.cc:10
virtual void f() const
Definition: exctest3.cc:12
virtual ~Exception()
Definition: exctest3.cc:11
Definition: exctest2.cc:14
virtual void f() const
Definition: exctest3.cc:20
virtual ~Oops()
Definition: exctest3.cc:19
Oops(const char s[])
Definition: exctest3.cc:18
int main()
Definition: exctest3.cc:24