1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
// ----------------------------------------------------------------------
//
// testThrowFrom.cc - test the ZMthrow_from() method,
// and the ZMexValidationStyle behavior,
// and setName, setSeverity, setFacility.
//
// History:
// 10-Apr-2001 mf Initial draft testing just ZMthrow_from()
// 11-Apr-2001 mf Test the other enhancements.
// 12-Jun-2002 web Insert conditional try-catch to allow testing in
// presence of true exceptions
//
// ----------------------------------------------------------------------
#include "CLHEP/Exceptions/ZMthrow.h"
#include "CLHEP/Exceptions/ZMexception.h"
using namespace zmex;
ZMexStandardDefinition( ZMexception, ZMxTest );
ZMexClassInfo ZMxTest::_classInfo(
"ZMxTest", "Test", ZMexSEVERE );
int main() {
// std::cout << "starting...\n";
// Not: ZMexception::setHandler( ZMexIgnoreAlways() ) ;
// Instead:
ZMxTest::setSeverity( ZMexWARNING ); // Which should not abort
ZMexception::setLogger( ZMexValidationStyle(std::cout) ) ;
// std::cout << "throwing...\n";
ZMthrow_from( ZMxTest("Artificial Exception"), 1000,
"directory/subdirectory/fictitious.file" );
ZMthrow_from( ZMxTest("Artificial backslash Exception"), 4000,
"directory/subdirectory\\fictitious.file" );
ZMthrow_from( ZMxTest("Artificial no slash Exception"), 4000,
"fictitious.file" );
ZMthrow( ZMxTest("Normal exception") );
ZMxTest::setName("MyExName");
ZMthrow( ZMxTest("Exception with new name") );
ZMxTest::setFacility("newFacility");
ZMthrow( ZMxTest("Exception from new facility") );
// -------------
// Done, go home
// -------------
ZMexception::setLogger( ZMexLogAlways(std::cout) ) ;
ZMxTest::setSeverity( ZMexERROR ); // Which should not abort
#ifndef DEFECT_NO_EXCEPTIONS
try {
#endif
ZMthrow( ZMxTest("Ordinary Error") );
#ifndef DEFECT_NO_EXCEPTIONS
}
catch( ZMexception & e ) {
std::cerr << "Caught: " << e.name() << "\n";
}
#endif
return 0;
} // main()
|