CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
ZMthrow.h
Go to the documentation of this file.
1#ifndef ZMTHROW_H
2#define ZMTHROW_H
3
4// ----------------------------------------------------------------------
5//
6// ZMthrow.h - macro definition for the ZMthrow macro, tand function
7// declarations for ZMthrow_from() and ZMthrow_().
8//
9// ZMthrow(x) calls ZMthrow_ but adds on the line and file arguments.
10// It either throws or not, depending on the return value of ZMthrow_.
11//
12// ZMthrow_from(x,line,file) calls ZMthrow_ using the supplied line and file
13// file arguments. Again, it either throws or not, depending on the return
14// value of ZMthrow_.
15//
16// ZMthrow_(), should not be used directly by user code, but is defined in
17// ZMthrow.cc for use by the ZMthrow macro and by ZMthrow_from.
18//
19// NOTE -- ZMthrow() and ZMthrow_from() are NOT in namespace zmex::
20// ZMthrow() is NOT namespace qualified; it is a macro.
21// ZMthrow_from() is NOT namespace qualified; it is a macro.
22//
23// Revision History
24// 970910 MF Initial version
25// 970916 WEB Update per code review
26// 970917 WEB Update per code review 2
27// 970918 PGC Replace monolitic if by do while loop
28// 971113 WEB Correct minor typo
29// 980615 WEB Add namespace support
30// 000218 WEB Replace NOTHROW by DEFECT_NO_EXCEPTIONS for
31// ISOcxx compatibility
32// 000512 WEB DEBUG corrections; remove useless reference in
33// NO_EXCEPTIONS definition
34// 010409 MF ZMthrow_from()
35// 010413 MF Include ZMenvironment and make other changes to
36// make sure namespaces are treated properly.
37// 031105 LG Get rid of all ZMutility references
38//
39// ----------------------------------------------------------------------
40
41#ifndef ZMEXACTION_H
42 #include "CLHEP/Exceptions/ZMexAction.h"
43#endif
44
45#include <stdlib.h> // for abort()
46#include <string>
47
48/* DEBUG #include <iostream> // for cerr */
49
50
51namespace zmex {
52
53
54class ZMexception;
55
56
57//*******************
58//
59// ZMthrow_from macro
60//
61//*******************
62
63
64#ifdef DEFECT_NO_EXCEPTIONS
65
66#define ZMthrow_from(userExcept, line, file ) \
67do { \
68 if ( zmex::ZMthrow_( userExcept, line, file ) == \
69 zmex::ZMexThrowIt ) { \
70 abort(); } \
71} while (false) \
72
73#else
74
75#define ZMthrow_from(userExcept, line, file ) \
76do { \
77 try { throw userExcept; } \
78 catch ( const zmex::ZMexception & x ) { \
79 if ( zmex::ZMthrow_( x, line, file ) == \
80 zmex::ZMexThrowIt ) { \
81 throw; \
82 } \
83 } \
84} while (false) \
85
86#endif // NOTHROW
87
88//
89// End of the ZMthrow_from macro, which should NOT end with a semicolon.
90
91//**************
92//
93// ZMthrow macro
94//
95//**************
96
97#define ZMthrow(userExcept) ZMthrow_from(userExcept, __LINE__, __FILE__)
98
99//
100// End of the ZMthrow macro, which should NOT end with a semicolon.
101
102// NOTE - This is a macro. It has to be a monolithic statement so that a
103// construct like
104// if (xxx) ZMthrow(ZMxAbc); else dowhatever;
105// works. Since the content CANNOT therefore be in a block, we use
106// a do-while loop that will be executed exactly once.
107
108//***********
109//
110// ZMthrow_()
111//
112//***********
113
115 const ZMexception & userException
116, int lineNum
117, const char fileName[]
118);
119
120} // namespace zmex
121
122
123
124#endif // ZMTHROW_H
Definition: ZMerrno.h:52
ZMexAction
Definition: ZMexAction.h:20
ZMexAction ZMthrow_(const ZMexception &userException, int lineNum, const char fileName[])
Definition: ZMthrow.cc:35