CLHEP 2.0.4.7 Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 // ---------------------------------------------------------------------- 00002 // 00003 // testThrowFrom.cc - test the ZMthrow_from() method, 00004 // and the ZMexValidationStyle behavior, 00005 // and setName, setSeverity, setFacility. 00006 // 00007 // History: 00008 // 10-Apr-2001 mf Initial draft testing just ZMthrow_from() 00009 // 11-Apr-2001 mf Test the other enhancements. 00010 // 12-Jun-2002 web Insert conditional try-catch to allow testing in 00011 // presence of true exceptions 00012 // 00013 // ---------------------------------------------------------------------- 00014 00015 #include "CLHEP/Exceptions/ZMthrow.h" 00016 #include "CLHEP/Exceptions/ZMexception.h" 00017 00018 using namespace zmex; 00019 00020 ZMexStandardDefinition( ZMexception, ZMxTest ); 00021 ZMexClassInfo ZMxTest::_classInfo( 00022 "ZMxTest", "Test", ZMexSEVERE ); 00023 00024 int main() { 00025 00026 // std::cout << "starting...\n"; 00027 00028 00029 // Not: ZMexception::setHandler( ZMexIgnoreAlways() ) ; 00030 // Instead: 00031 ZMxTest::setSeverity( ZMexWARNING ); // Which should not abort 00032 00033 ZMexception::setLogger( ZMexValidationStyle(std::cout) ) ; 00034 00035 // std::cout << "throwing...\n"; 00036 00037 ZMthrow_from( ZMxTest("Artificial Exception"), 1000, 00038 "directory/subdirectory/fictitious.file" ); 00039 00040 ZMthrow_from( ZMxTest("Artificial backslash Exception"), 4000, 00041 "directory/subdirectory\\fictitious.file" ); 00042 00043 ZMthrow_from( ZMxTest("Artificial no slash Exception"), 4000, 00044 "fictitious.file" ); 00045 00046 ZMthrow( ZMxTest("Normal exception") ); 00047 00048 ZMxTest::setName("MyExName"); 00049 ZMthrow( ZMxTest("Exception with new name") ); 00050 00051 ZMxTest::setFacility("newFacility"); 00052 ZMthrow( ZMxTest("Exception from new facility") ); 00053 00054 // ------------- 00055 // Done, go home 00056 // ------------- 00057 00058 ZMexception::setLogger( ZMexLogAlways(std::cout) ) ; 00059 00060 ZMxTest::setSeverity( ZMexERROR ); // Which should not abort 00061 #ifndef DEFECT_NO_EXCEPTIONS 00062 try { 00063 #endif 00064 ZMthrow( ZMxTest("Ordinary Error") ); 00065 #ifndef DEFECT_NO_EXCEPTIONS 00066 } 00067 catch( ZMexception & e ) { 00068 std::cerr << "Caught: " << e.name() << "\n"; 00069 } 00070 #endif 00071 00072 return 0; 00073 00074 } // main()