CLHEP VERSION Reference Documentation
CLHEP Home Page
CLHEP Documentation
CLHEP Bug Reports
Exceptions
test
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
18
using namespace
zmex
;
19
20
ZMexStandardDefinition
(
ZMexception
, ZMxTest );
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()
ZMthrow_from
#define ZMthrow_from(userExcept, line, file)
Definition:
CLHEP/Exceptions/ZMthrow.h:75
zmex::ZMexValidationStyle
Definition:
CLHEP/Exceptions/ZMexLogger.h:220
ZMthrow
#define ZMthrow(userExcept)
Definition:
CLHEP/Exceptions/ZMthrow.h:97
zmex
Definition:
CLHEP/Exceptions/ZMerrno.h:52
ZMexStandardDefinition
ZMexStandardDefinition(ZMexception, ZMxTest)
ZMthrow.h
zmex::ZMexception::name
virtual std::string name() const
Definition:
ZMexception.cc:104
main
int main()
Definition:
testThrowFrom.cc:24
zmex::ZMexception
Definition:
CLHEP/Exceptions/ZMexception.h:163
zmex::ZMexClassInfo
Definition:
CLHEP/Exceptions/ZMexClassInfo.h:94
zmex::ZMexSEVERE
@ ZMexSEVERE
Definition:
CLHEP/Exceptions/ZMexSeverity.h:53
zmex::ZMexLogAlways
Definition:
CLHEP/Exceptions/ZMexLogger.h:127
ZMexception.h
zmex::ZMexERROR
@ ZMexERROR
Definition:
CLHEP/Exceptions/ZMexSeverity.h:46
zmex::ZMexWARNING
@ ZMexWARNING
Definition:
CLHEP/Exceptions/ZMexSeverity.h:41
Generated by
1.8.17