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
12using namespace zmex;
13
14#include <fstream>
15using 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
28ZMexClassInfo ZMxTop::_classInfo( "ZMxTop", "HepTuple" );
29
30ZMexStandardDefinition( ZMxTop, ZMxHepTuple );
31ZMexClassInfo ZMxHepTuple::_classInfo( "ZMxHeptuple", "HepTuple" );
32
34ZMexClassInfo ZMxTop2::_classInfo( "ZMxTop2", "Other Top Exception" );
35
36ZMexStandardDefinition( ZMxTop2, ZMxHepTuple2 );
37ZMexClassInfo ZMxHepTuple2::_classInfo( "ZMxHepTuple2", "Other HepTuple" );
38
39ZMexStandardDefinition( ZMxHepTuple2, ZMxColumn );
40ZMexClassInfo ZMxColumn::_classInfo( "ZMxColumn", "Column excep" );
41
42
43int 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}
#define ZMthrow(userExcept)
unsigned int setMax(unsigned int limit)
Definition: ZMerrno.cc:146
unsigned int size() const
const ZMexception * get(unsigned int k=0) const
Definition: ZMerrno.cc:94
std::string message() const
virtual std::string name() const
Definition: ZMexception.cc:104
ZMexStandardDefinition(ZMexception, ZMxTop)
int main()
ZMerrnoList ZMerrno