CLHEP VERSION Reference Documentation
CLHEP Home Page
CLHEP Documentation
CLHEP Bug Reports
Main Page
Namespaces
Classes
Files
File List
File Members
Exceptions
test
excDblThrow.cc
Go to the documentation of this file.
1
// Explore single- and double-throwing techniques
2
3
4
#include <iostream>
5
using
std::cerr;
6
7
8
struct
B
{
9
10
B
() { cerr <<
"make B\n"
; }
11
B
(
B
const
&
b
) { cerr <<
"copy B\n"
; }
12
virtual
char
type
()
const
{
return
'B'
; };
13
14
};
// struct B
15
16
17
struct
D
:
public
B
{
18
19
D
() { cerr <<
"make D\n"
; }
20
D
(
const
D
& d ) :
B
( d ) { cerr <<
"copy D\n"
; }
21
virtual
char
type
()
const
{
return
'D'
; };
22
23
};
// struct D
24
25
26
#define single( obj ) \
27
cerr << "\nsingle( " #obj " )\n"; \
28
const B & ref = obj; \
29
throw ref;
30
31
32
#define double( obj ) \
33
cerr << "\ndouble( " #obj " )\n"; \
34
try { throw obj; } \
35
catch ( const B & x ) { throw; }
36
37
38
void
f
(
void
g
() ) {
39
40
try
{
g
(); }
41
//catch( D const & x ) { cerr << "Caught D is " << x.type() << '\n'; }
42
catch
(
B
const
& x ) { cerr <<
"Caught B is "
<< x.
type
() <<
'\n'
; }
43
44
}
45
46
47
void
test1
() {
double
(
B
() ); }
48
void
test2
() {
double
(
D
() ); }
49
void
test3
() {
single
(
B
() ); }
50
void
test4
() {
single
(
D
() ); }
51
52
53
int
main
() {
54
55
cerr <<
"\nTesting double throws:\n"
;
56
f
(
test1
);
57
f
(
test2
);
58
59
cerr <<
"\nTesting single throws:\n"
;
60
f
(
test3
);
61
f
(
test4
);
62
63
}
Generated on Mon May 6 2013 04:04:10 for CLHEP by
1.8.1.2