CLHEP 2.0.4.7 Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // This program tests the DEFECT_NO_EXCEPTIONS version of the Exceptions package: 00002 // 12-Dec-2001 WEB Avoid signed/unsigned comparison warnings 00003 00004 #ifndef DEFECT_NO_EXCEPTIONS 00005 #define DEFECT_NO_EXCEPTIONS 1 00006 #endif 00007 00008 00009 #include "CLHEP/Exceptions/ZMthrow.h" 00010 #include "CLHEP/Exceptions/ZMexception.h" 00011 #include "CLHEP/Exceptions/ZMerrno.h" 00012 using namespace zmex; 00013 00014 #include <fstream> 00015 using namespace std; 00016 00017 00018 // We try to have this test program test several cases, including 00019 // several actual throws, so we assume that the DEFECT_NO_EXCEPTIONS version of 00020 // the ZMthrow macro will use exit() or abort() and so override 00021 // those behaviors in order to keep going for multiple testing herein: 00022 #include <stdio.h> 00023 #define exit( x ) printf( "this is an actual exit\n", x ); 00024 #define abort( ) printf( "this is an actual abort\n" ); 00025 00026 00027 ZMexStandardDefinition( ZMexception, ZMxTop ); 00028 ZMexClassInfo ZMxTop::_classInfo( "ZMxTop", "HepTuple" ); 00029 00030 ZMexStandardDefinition( ZMxTop, ZMxHepTuple ); 00031 ZMexClassInfo ZMxHepTuple::_classInfo( "ZMxHeptuple", "HepTuple" ); 00032 00033 ZMexStandardDefinition( ZMexception, ZMxTop2 ); 00034 ZMexClassInfo ZMxTop2::_classInfo( "ZMxTop2", "Other Top Exception" ); 00035 00036 ZMexStandardDefinition( ZMxTop2, ZMxHepTuple2 ); 00037 ZMexClassInfo ZMxHepTuple2::_classInfo( "ZMxHepTuple2", "Other HepTuple" ); 00038 00039 ZMexStandardDefinition( ZMxHepTuple2, ZMxColumn ); 00040 ZMexClassInfo ZMxColumn::_classInfo( "ZMxColumn", "Column excep" ); 00041 00042 00043 int main ( ) { 00044 00045 ZMxTop::setHandler( ZMexIgnoreAlways( ) ); 00046 ZMxHepTuple::setHandler( ZMexThrowAlways( ) ); 00047 00048 printf( "Try to ignore a ZMxTop with msg -top-\n" ); 00049 ZMthrow( ZMxTop( "top" ) ); 00050 printf( "Try to throw a ZMxHepTuple with msg -bottom-\n" ); 00051 ZMthrow( ZMxHepTuple( "bottom" ) ); 00052 00053 printf( "Try to throw a top exception with a ZMhParentHandler\n" ); 00054 ZMthrow( ZMxTop2( "top2" ) ); 00055 00056 printf( "Try to throw a ZMxColumn\n" ); 00057 ZMthrow( ZMxColumn( "a column error" ) ); 00058 00059 ZMxHepTuple2::setHandler( ZMexIgnoreNextN( 3 ) ); 00060 00061 std::ofstream logfile( "exception.report" ); 00062 ZMxHepTuple2::setLogger( ZMexLogAlways( logfile ) ); 00063 00064 printf( "Try to throw a ZMxTop2\n" ); 00065 ZMthrow( ZMxTop2( "top2" ) ); 00066 00067 printf( "Try to ignore a ZMxHepTuple2\n" ); 00068 ZMthrow( ZMxHepTuple2( "a heptuple error" ) ); 00069 00070 //ZMxColumn::logNMore( 4 ); 00071 printf( "Try to ignore a ZMxColumn\n" ); 00072 ZMthrow( ZMxColumn( "2 column error" ) ); 00073 printf( "Try to ignore a ZMxColumn\n" ); 00074 ZMthrow( ZMxColumn( "3 column error" ) ); 00075 printf( "Try to throw a ZMxColumn\n" ); 00076 ZMthrow( ZMxColumn( "4 column error" ) ); 00077 printf( "Try to throw a ZMxColumn\n" ); 00078 ZMthrow( ZMxColumn( "5 column error" ) ); 00079 00080 std::cout << "logged the following exceptions\n"; 00081 unsigned int s; 00082 for ( s = 0; s < ZMerrno.size( ); s++ ) { 00083 std::cout << ZMerrno.get( s )->name( ) << " : " << 00084 ZMerrno.get( s )->message( ) << std::endl; 00085 } 00086 std::cout << "Reset the length of ZMerrno to 4\n"; 00087 ZMerrno.setMax( 4 ); 00088 for ( s = 0; s < ZMerrno.size( ); s++ ) { 00089 std::cout << ZMerrno.get( s )->name( ) << " : " << 00090 ZMerrno.get( s )->message( ) << std::endl; 00091 } 00092 00093 return 0; 00094 }