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
8struct 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
17struct 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
38void 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
47void test1() { double( B() ); }
48void test2() { double( D() ); }
49void test3() { single( B() ); }
50void test4() { single( D() ); }
51
52
53int 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}
void test2()
Definition: excDblThrow.cc:48
void test1()
Definition: excDblThrow.cc:47
#define double(obj)
Definition: excDblThrow.cc:32
void test4()
Definition: excDblThrow.cc:50
void f(void g())
Definition: excDblThrow.cc:38
void test3()
Definition: excDblThrow.cc:49
#define single(obj)
Definition: excDblThrow.cc:26
int main()
Definition: excDblThrow.cc:53
Definition: excDblThrow.cc:8
B(B const &b)
Definition: excDblThrow.cc:11
B()
Definition: excDblThrow.cc:10
virtual char type() const
Definition: excDblThrow.cc:12
Definition: excDblThrow.cc:17
D(const D &d)
Definition: excDblThrow.cc:20
D()
Definition: excDblThrow.cc:19
virtual char type() const
Definition: excDblThrow.cc:21
int g(shared_ptr< X >)