CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
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
9#include "CLHEP/Exceptions/ZMthrow.h"
10#include "CLHEP/Exceptions/ZMexception.h"
11#include "CLHEP/Exceptions/ZMexAction.h"
12#include "CLHEP/Exceptions/ZMexClassInfo.h"
13#include "CLHEP/Exceptions/ZMexSeverity.h"
14#include "CLHEP/Exceptions/ZMerrno.h"
15
16using namespace zmex;
17
18#include <iostream>
19#include <fstream>
20
21using namespace std;
22
23
24// We try to have this test program test several cases, including
25// several actual throws, so we assume that the DEFECT_NO_EXCEPTIONS version of
26// the ZMthrow macro will use exit() or abort() and so override
27// those behaviors in order to keep going for multiple testing herein:
28#include <stdio.h>
29#define exit( x ) printf( "this is an actual exit\n", x );
30#define abort( ) printf( "this is an actual abort\n" );
31
32
34ZMexClassInfo ZMxTop::_classInfo( "ZMxTop", "HepTuple" );
35
36ZMexStandardDefinition( ZMxTop, ZMxHepTuple );
37ZMexClassInfo ZMxHepTuple::_classInfo( "ZMxHeptuple", "HepTuple" );
38
40ZMexClassInfo ZMxTop2::_classInfo( "ZMxTop2", "Other Top Exception" );
41
42ZMexStandardDefinition( ZMxTop2, ZMxHepTuple2 );
43ZMexClassInfo ZMxHepTuple2::_classInfo( "ZMxHepTuple2", "Other HepTuple" );
44
45ZMexStandardDefinition( ZMxHepTuple2, ZMxColumn );
46ZMexClassInfo ZMxColumn::_classInfo( "ZMxColumn", "Column excep" );
47
48
49int main ( ) {
50
51 ZMxTop::setHandler( ZMexIgnoreAlways( ) );
52 ZMxHepTuple::setHandler( ZMexThrowAlways( ) );
53
54 printf( "Try to ignore a ZMxTop with msg -top-\n" );
55 ZMthrow( ZMxTop( "top" ) );
56 printf( "Try to throw a ZMxHepTuple with msg -bottom-\n" );
57 ZMthrow( ZMxHepTuple( "bottom" ) );
58
59 printf( "Try to throw a top exception with a ZMhParentHandler\n" );
60 ZMthrow( ZMxTop2( "top2" ) );
61
62 printf( "Try to throw a ZMxColumn\n" );
63 ZMthrow( ZMxColumn( "a column error" ) );
64
65 ZMxHepTuple2::setHandler( ZMexIgnoreNextN( 3 ) );
66
67 std::ofstream logfile( "exception.report" );
68 ZMxHepTuple2::setLogger( ZMexLogAlways( logfile ) );
69
70 printf( "Try to throw a ZMxTop2\n" );
71 ZMthrow( ZMxTop2( "top2" ) );
72
73 printf( "Try to ignore a ZMxHepTuple2\n" );
74 ZMthrow( ZMxHepTuple2( "a heptuple error" ) );
75
76 //ZMxColumn::logNMore( 4 );
77 printf( "Try to ignore a ZMxColumn\n" );
78 ZMthrow( ZMxColumn( "2 column error" ) );
79 printf( "Try to ignore a ZMxColumn\n" );
80 ZMthrow( ZMxColumn( "3 column error" ) );
81 printf( "Try to throw a ZMxColumn\n" );
82 ZMthrow( ZMxColumn( "4 column error" ) );
83 printf( "Try to throw a ZMxColumn\n" );
84 ZMthrow( ZMxColumn( "5 column error" ) );
85
86 std::cout << "logged the following exceptions\n";
87 unsigned int s;
88 for ( s = 0; s < ZMerrno.size( ); s++ ) {
89 std::cout << ZMerrno.get( s )->name( ) << " : " <<
90 ZMerrno.get( s )->message( ) << std::endl;
91 }
92 std::cout << "Reset the length of ZMerrno to 4\n";
93 ZMerrno.setMax( 4 );
94 for ( s = 0; s < ZMerrno.size( ); s++ ) {
95 std::cout << ZMerrno.get( s )->name( ) << " : " <<
96 ZMerrno.get( s )->message( ) << std::endl;
97 }
98
99 return 0;
100}
#define ZMexStandardDefinition(Parent, Class)
Definition: ZMexception.h:523
#define ZMthrow(userExcept)
Definition: ZMthrow.h:97
unsigned int setMax(unsigned int limit)
Definition: ZMerrno.cc:147
unsigned int size() const
const ZMexception * get(unsigned int k=0) const
Definition: ZMerrno.cc:95
std::string message() const
virtual std::string name() const
Definition: ZMexception.cc:106
int main()
Definition: ZMerrno.h:52
ZMerrnoList ZMerrno
Definition: ZMerrno.cc:40