CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
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
15#include "CLHEP/Exceptions/ZMthrow.h"
16#include "CLHEP/Exceptions/ZMexception.h"
17#include "CLHEP/Exceptions/ZMexAction.h"
18#include "CLHEP/Exceptions/ZMexClassInfo.h"
19#include "CLHEP/Exceptions/ZMexSeverity.h"
20
21#include <iostream>
22using namespace zmex;
23
25ZMexClassInfo ZMxTest::_classInfo(
26 "ZMxTest", "Test", ZMexSEVERE );
27
28int main() {
29
30// std::cout << "starting...\n";
31
32
33// Not: ZMexception::setHandler( ZMexIgnoreAlways() ) ;
34// Instead:
35 ZMxTest::setSeverity( ZMexWARNING ); // Which should not abort
36
37 ZMexception::setLogger( ZMexValidationStyle(std::cout) ) ;
38
39// std::cout << "throwing...\n";
40
41 ZMthrow_from( ZMxTest("Artificial Exception"), 1000,
42 "directory/subdirectory/fictitious.file" );
43
44 ZMthrow_from( ZMxTest("Artificial backslash Exception"), 4000,
45 "directory/subdirectory\\fictitious.file" );
46
47 ZMthrow_from( ZMxTest("Artificial no slash Exception"), 4000,
48 "fictitious.file" );
49
50 ZMthrow( ZMxTest("Normal exception") );
51
52 ZMxTest::setName("MyExName");
53 ZMthrow( ZMxTest("Exception with new name") );
54
55 ZMxTest::setFacility("newFacility");
56 ZMthrow( ZMxTest("Exception from new facility") );
57
58 // -------------
59 // Done, go home
60 // -------------
61
62 ZMexception::setLogger( ZMexLogAlways(std::cout) ) ;
63
64 ZMxTest::setSeverity( ZMexERROR ); // Which should not abort
65#ifndef DEFECT_NO_EXCEPTIONS
66 try {
67#endif
68 ZMthrow( ZMxTest("Ordinary Error") );
69#ifndef DEFECT_NO_EXCEPTIONS
70 }
71 catch( ZMexception & e ) {
72 std::cerr << "Caught: " << e.name() << "\n";
73 }
74#endif
75
76 return 0;
77
78} // main()
#define ZMexStandardDefinition(Parent, Class)
Definition: ZMexception.h:523
#define ZMthrow(userExcept)
Definition: ZMthrow.h:97
#define ZMthrow_from(userExcept, line, file)
Definition: ZMthrow.h:75
virtual std::string name() const
Definition: ZMexception.cc:106
Definition: ZMerrno.h:52
@ ZMexWARNING
Definition: ZMexSeverity.h:41
@ ZMexSEVERE
Definition: ZMexSeverity.h:53
@ ZMexERROR
Definition: ZMexSeverity.h:46
int main()