CLHEP
2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
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
}
test2
void test2()
Definition:
excDblThrow.cc:48
test1
void test1()
Definition:
excDblThrow.cc:47
double
#define double(obj)
Definition:
excDblThrow.cc:32
test4
void test4()
Definition:
excDblThrow.cc:50
f
void f(void g())
Definition:
excDblThrow.cc:38
test3
void test3()
Definition:
excDblThrow.cc:49
single
#define single(obj)
Definition:
excDblThrow.cc:26
main
int main()
Definition:
excDblThrow.cc:53
B
Definition:
excDblThrow.cc:8
B::B
B(B const &b)
Definition:
excDblThrow.cc:11
B::B
B()
Definition:
excDblThrow.cc:10
B::type
virtual char type() const
Definition:
excDblThrow.cc:12
D
Definition:
excDblThrow.cc:17
D::D
D(const D &d)
Definition:
excDblThrow.cc:20
D::D
D()
Definition:
excDblThrow.cc:19
D::type
virtual char type() const
Definition:
excDblThrow.cc:21
g
int g(shared_ptr< X >)
Definition:
testSharedPtrConvertible.cc:54
CLHEP-CLHEP_2_4_6_4
Exceptions
test
excDblThrow.cc
Generated by
1.9.6