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

exctestNothrow.cc
Go to the documentation of this file.
1 // This program tests the DEFECT_NO_EXCEPTIONS version of the Exceptions package:
2 // 12-Dec-2001 WEB Avoid signed/unsigned comparison warnings
3 
4 #ifndef DEFECT_NO_EXCEPTIONS
5  #define DEFECT_NO_EXCEPTIONS 1
6 #endif
7 
8 
12 using namespace zmex;
13 
14 #include <fstream>
15 using namespace std;
16 
17 
18 // We try to have this test program test several cases, including
19 // several actual throws, so we assume that the DEFECT_NO_EXCEPTIONS version of
20 // the ZMthrow macro will use exit() or abort() and so override
21 // those behaviors in order to keep going for multiple testing herein:
22 #include <stdio.h>
23 #define exit( x ) printf( "this is an actual exit\n", x );
24 #define abort( ) printf( "this is an actual abort\n" );
25 
26 
28 ZMexClassInfo ZMxTop::_classInfo( "ZMxTop", "HepTuple" );
29 
30 ZMexStandardDefinition( ZMxTop, ZMxHepTuple );
31 ZMexClassInfo ZMxHepTuple::_classInfo( "ZMxHeptuple", "HepTuple" );
32 
34 ZMexClassInfo ZMxTop2::_classInfo( "ZMxTop2", "Other Top Exception" );
35 
36 ZMexStandardDefinition( ZMxTop2, ZMxHepTuple2 );
37 ZMexClassInfo ZMxHepTuple2::_classInfo( "ZMxHepTuple2", "Other HepTuple" );
38 
39 ZMexStandardDefinition( ZMxHepTuple2, ZMxColumn );
40 ZMexClassInfo ZMxColumn::_classInfo( "ZMxColumn", "Column excep" );
41 
42 
43 int main ( ) {
44 
45  ZMxTop::setHandler( ZMexIgnoreAlways( ) );
46  ZMxHepTuple::setHandler( ZMexThrowAlways( ) );
47 
48  printf( "Try to ignore a ZMxTop with msg -top-\n" );
49  ZMthrow( ZMxTop( "top" ) );
50  printf( "Try to throw a ZMxHepTuple with msg -bottom-\n" );
51  ZMthrow( ZMxHepTuple( "bottom" ) );
52 
53  printf( "Try to throw a top exception with a ZMhParentHandler\n" );
54  ZMthrow( ZMxTop2( "top2" ) );
55 
56  printf( "Try to throw a ZMxColumn\n" );
57  ZMthrow( ZMxColumn( "a column error" ) );
58 
59  ZMxHepTuple2::setHandler( ZMexIgnoreNextN( 3 ) );
60 
61  std::ofstream logfile( "exception.report" );
62  ZMxHepTuple2::setLogger( ZMexLogAlways( logfile ) );
63 
64  printf( "Try to throw a ZMxTop2\n" );
65  ZMthrow( ZMxTop2( "top2" ) );
66 
67  printf( "Try to ignore a ZMxHepTuple2\n" );
68  ZMthrow( ZMxHepTuple2( "a heptuple error" ) );
69 
70  //ZMxColumn::logNMore( 4 );
71  printf( "Try to ignore a ZMxColumn\n" );
72  ZMthrow( ZMxColumn( "2 column error" ) );
73  printf( "Try to ignore a ZMxColumn\n" );
74  ZMthrow( ZMxColumn( "3 column error" ) );
75  printf( "Try to throw a ZMxColumn\n" );
76  ZMthrow( ZMxColumn( "4 column error" ) );
77  printf( "Try to throw a ZMxColumn\n" );
78  ZMthrow( ZMxColumn( "5 column error" ) );
79 
80  std::cout << "logged the following exceptions\n";
81  unsigned int s;
82  for ( s = 0; s < ZMerrno.size( ); s++ ) {
83  std::cout << ZMerrno.get( s )->name( ) << " : " <<
84  ZMerrno.get( s )->message( ) << std::endl;
85  }
86  std::cout << "Reset the length of ZMerrno to 4\n";
87  ZMerrno.setMax( 4 );
88  for ( s = 0; s < ZMerrno.size( ); s++ ) {
89  std::cout << ZMerrno.get( s )->name( ) << " : " <<
90  ZMerrno.get( s )->message( ) << std::endl;
91  }
92 
93  return 0;
94 }
ZMthrow
#define ZMthrow(userExcept)
Definition: CLHEP/Exceptions/ZMthrow.h:97
zmex
Definition: CLHEP/Exceptions/ZMerrno.h:52
ZMthrow.h
zmex::ZMexThrowAlways
Definition: CLHEP/Exceptions/ZMexHandler.h:132
zmex::ZMexception::name
virtual std::string name() const
Definition: ZMexception.cc:104
zmex::ZMerrno
ZMerrnoList ZMerrno
Definition: Exceptions/ZMerrno.h:122
zmex::ZMerrnoList::get
const ZMexception * get(unsigned int k=0) const
Definition: ZMerrno.cc:94
zmex::ZMexIgnoreNextN
Definition: CLHEP/Exceptions/ZMexHandler.h:177
zmex::ZMexception
Definition: CLHEP/Exceptions/ZMexception.h:163
ZMexStandardDefinition
ZMexStandardDefinition(ZMexception, ZMxTop)
ZMerrno.h
zmex::ZMexClassInfo
Definition: CLHEP/Exceptions/ZMexClassInfo.h:94
zmex::ZMerrnoList::setMax
unsigned int setMax(unsigned int limit)
Definition: ZMerrno.cc:146
main
int main()
Definition: exctestNothrow.cc:43
ZMexIgnoreAlways
The given behavior will apply to any exceptions ZMthrow n after the handler has been established Available handlers Here is a list of the five standard handlers that are defined via the Exceptions package Each is accompanied by a brief description of its after become the object of a C throw ZMexIgnoreAlways() the ZMthrow 'n exception instance will be handled
zmex::ZMexLogAlways
Definition: CLHEP/Exceptions/ZMexLogger.h:127
ZMexception.h
zmex::ZMexception::message
std::string message() const
s
Methods applicble to containers of as in std::list< LorentzVector > s
Definition: keyMergeIssues.doc:328
zmex::ZMerrnoList::size
unsigned int size() const