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>
4
using
std::cerr;
5
using
std::endl;
6
7
8
class
Exception
{
9
public
:
10
Exception
(
const
char
[] ) {}
11
virtual
~Exception
() {}
12
virtual
void
f
()
const
{ cerr <<
"Exception::f()"
<< endl; }
13
};
14
15
16
class
Oops
:
public
Exception
{
17
public
:
18
Oops
(
const
char
s[] ) :
Exception
( s ) {}
19
virtual
~Oops
() {}
20
virtual
void
f
()
const
{ cerr <<
"Oops::f()"
<< endl; }
21
};
22
23
24
int
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
Definition:
exctest2.cc:8
Exception::Exception
Exception(const char[])
Definition:
exctest3.cc:10
Exception::f
virtual void f() const
Definition:
exctest3.cc:12
Exception::~Exception
virtual ~Exception()
Definition:
exctest3.cc:11
Oops
Definition:
exctest2.cc:14
Oops::f
virtual void f() const
Definition:
exctest3.cc:20
Oops::~Oops
virtual ~Oops()
Definition:
exctest3.cc:19
Oops::Oops
Oops(const char s[])
Definition:
exctest3.cc:18
main
int main()
Definition:
exctest3.cc:24
CLHEP-CLHEP_2_4_6_4
Exceptions
test
exctest3.cc
Generated by
1.9.6