CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

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