CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

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