CLHEP VERSION Reference Documentation
CLHEP Home Page CLHEP Documentation CLHEP Bug Reports |
00001 #ifndef ZMTHROW_H 00002 #define ZMTHROW_H 00003 00004 // ---------------------------------------------------------------------- 00005 // 00006 // ZMthrow.h - macro definition for the ZMthrow macro, tand function 00007 // declarations for ZMthrow_from() and ZMthrow_(). 00008 // 00009 // ZMthrow(x) calls ZMthrow_ but adds on the line and file arguments. 00010 // It either throws or not, depending on the return value of ZMthrow_. 00011 // 00012 // ZMthrow_from(x,line,file) calls ZMthrow_ using the supplied line and file 00013 // file arguments. Again, it either throws or not, depending on the return 00014 // value of ZMthrow_. 00015 // 00016 // ZMthrow_(), should not be used directly by user code, but is defined in 00017 // ZMthrow.cc for use by the ZMthrow macro and by ZMthrow_from. 00018 // 00019 // NOTE -- ZMthrow() and ZMthrow_from() are NOT in namespace zmex:: 00020 // ZMthrow() is NOT namespace qualified; it is a macro. 00021 // ZMthrow_from() is NOT namespace qualified; it is a macro. 00022 // 00023 // Revision History 00024 // 970910 MF Initial version 00025 // 970916 WEB Update per code review 00026 // 970917 WEB Update per code review 2 00027 // 970918 PGC Replace monolitic if by do while loop 00028 // 971113 WEB Correct minor typo 00029 // 980615 WEB Add namespace support 00030 // 000218 WEB Replace NOTHROW by DEFECT_NO_EXCEPTIONS for 00031 // ISOcxx compatibility 00032 // 000512 WEB DEBUG corrections; remove useless reference in 00033 // NO_EXCEPTIONS definition 00034 // 010409 MF ZMthrow_from() 00035 // 010413 MF Include ZMenvironment and make other changes to 00036 // make sure namespaces are treated properly. 00037 // 031105 LG Get rid of all ZMutility references 00038 // 00039 // ---------------------------------------------------------------------- 00040 00041 #ifndef ZMEXACTION_H 00042 #include "CLHEP/Exceptions/ZMexAction.h" 00043 #endif 00044 00045 #include <stdlib.h> // for abort() 00046 #include <string> 00047 00048 /* DEBUG #include <iostream> // for cerr */ 00049 00050 00051 namespace zmex { 00052 00053 00054 class ZMexception; 00055 00056 00057 //******************* 00058 // 00059 // ZMthrow_from macro 00060 // 00061 //******************* 00062 00063 00064 #ifdef DEFECT_NO_EXCEPTIONS 00065 00066 #define ZMthrow_from(userExcept, line, file ) \ 00067 do { \ 00068 if ( zmex::ZMthrow_( userExcept, line, file ) == \ 00069 zmex::ZMexThrowIt ) { \ 00070 abort(); } \ 00071 } while (false) \ 00072 00073 #else 00074 00075 #define ZMthrow_from(userExcept, line, file ) \ 00076 do { \ 00077 try { throw userExcept; } \ 00078 catch ( const zmex::ZMexception & x ) { \ 00079 if ( zmex::ZMthrow_( x, line, file ) == \ 00080 zmex::ZMexThrowIt ) { \ 00081 throw; \ 00082 } \ 00083 } \ 00084 } while (false) \ 00085 00086 #endif // NOTHROW 00087 00088 // 00089 // End of the ZMthrow_from macro, which should NOT end with a semicolon. 00090 00091 //************** 00092 // 00093 // ZMthrow macro 00094 // 00095 //************** 00096 00097 #define ZMthrow(userExcept) ZMthrow_from(userExcept, __LINE__, __FILE__) 00098 00099 // 00100 // End of the ZMthrow macro, which should NOT end with a semicolon. 00101 00102 // NOTE - This is a macro. It has to be a monolithic statement so that a 00103 // construct like 00104 // if (xxx) ZMthrow(ZMxAbc); else dowhatever; 00105 // works. Since the content CANNOT therefore be in a block, we use 00106 // a do-while loop that will be executed exactly once. 00107 00108 //*********** 00109 // 00110 // ZMthrow_() 00111 // 00112 //*********** 00113 00114 ZMexAction ZMthrow_( 00115 const ZMexception & userException 00116 , int lineNum 00117 , const char fileName[] 00118 ); 00119 00120 } // namespace zmex 00121 00122 00123 00124 #endif // ZMTHROW_H