MOAB: Mesh Oriented datABase
(version 5.4.1)
|
00001 #ifndef MOAB_ERROR_HANDLER_HPP 00002 #define MOAB_ERROR_HANDLER_HPP 00003 00004 #ifdef _WIN32 00005 #define __func__ __FUNCTION__ 00006 #endif 00007 00008 #include "moab/Types.hpp" 00009 00010 #include <sstream> 00011 #include <cstring> 00012 00013 namespace moab 00014 { 00015 00016 //! ErrorType - passed to the error handling routines indicating whether this is a new error 00017 //! (globally fatal or per-processor relevant) to be created, or an existing one to be handled 00018 enum ErrorType 00019 { 00020 MB_ERROR_TYPE_NEW_GLOBAL = 0, 00021 MB_ERROR_TYPE_NEW_LOCAL = 1, 00022 MB_ERROR_TYPE_EXISTING = 2 00023 }; 00024 00025 //! Initialize MOAB error handler (e.g. create a utility object for printing error output) 00026 void MBErrorHandler_Init(); 00027 00028 //! Finalize MOAB error handler (e.g. delete the utility object for printing error output) 00029 void MBErrorHandler_Finalize(); 00030 00031 //! Indicates whether MBErrorHandler_Init has been called 00032 bool MBErrorHandler_Initialized(); 00033 00034 //! Get information about the last error 00035 void MBErrorHandler_GetLastError( std::string& error ); 00036 00037 //! Routine that is called to create a new error or handle an existing one 00038 ErrorCode MBError( int line, 00039 const char* func, 00040 const char* file, 00041 const char* dir, 00042 ErrorCode err_code, 00043 const char* err_msg, 00044 ErrorType err_type ); 00045 00046 } // namespace moab 00047 00048 #define __FILENAME__ ( strrchr( __FILE__, '/' ) ? strrchr( __FILE__, '/' ) + 1 : __FILE__ ) 00049 00050 #define MBSTRINGIFY_( X ) #X 00051 #define MBSTRINGIFY( X ) MBSTRINGIFY_( X ) 00052 00053 #ifdef LOCDIR 00054 #define __MBSDIR__ MBSTRINGIFY( LOCDIR ) 00055 #else 00056 #define __MBSDIR__ "" 00057 #endif 00058 00059 //! Set a new error with the given error message (a string or a stream) and return the given error 00060 //! code Used in functions which return ErrorCode 00061 #define MB_SET_ERR( err_code, err_msg ) \ 00062 do \ 00063 { \ 00064 std::ostringstream err_ostr; \ 00065 err_ostr << err_msg; \ 00066 return moab::MBError( __LINE__, __func__, __FILENAME__, __MBSDIR__, err_code, err_ostr.str().c_str(), \ 00067 moab::MB_ERROR_TYPE_NEW_LOCAL ); \ 00068 } while( false ) 00069 00070 //! Set a new error with the given error message (a string or a stream) and return 00071 //! Used in functions which return void types (or have no return types at all, e.g. constructors) 00072 #define MB_SET_ERR_RET( err_msg ) \ 00073 do \ 00074 { \ 00075 std::ostringstream err_ostr; \ 00076 err_ostr << err_msg; \ 00077 moab::MBError( __LINE__, __func__, __FILENAME__, __MBSDIR__, moab::MB_FAILURE, err_ostr.str().c_str(), \ 00078 moab::MB_ERROR_TYPE_NEW_LOCAL ); \ 00079 return; \ 00080 } while( false ) 00081 00082 //! Set a new error with the given error message (a string or a stream) and return the given value 00083 //! Used in functions which return any data type 00084 #define MB_SET_ERR_RET_VAL( err_msg, ret_val ) \ 00085 do \ 00086 { \ 00087 std::ostringstream err_ostr; \ 00088 err_ostr << err_msg; \ 00089 moab::MBError( __LINE__, __func__, __FILENAME__, __MBSDIR__, moab::MB_FAILURE, err_ostr.str().c_str(), \ 00090 moab::MB_ERROR_TYPE_NEW_LOCAL ); \ 00091 return ret_val; \ 00092 } while( false ) 00093 00094 //! Set a new error with the given error message (a string or a stream) and continue 00095 //! Used in functions which return any data type 00096 #define MB_SET_ERR_CONT( err_msg ) \ 00097 do \ 00098 { \ 00099 std::ostringstream err_ostr; \ 00100 err_ostr << err_msg; \ 00101 moab::MBError( __LINE__, __func__, __FILENAME__, __MBSDIR__, moab::MB_FAILURE, err_ostr.str().c_str(), \ 00102 moab::MB_ERROR_TYPE_NEW_LOCAL ); \ 00103 } while( false ) 00104 00105 //! Similar to MB_SET_ERR except that the error is considered globally fatal 00106 #define MB_SET_GLB_ERR( err_code, err_msg ) \ 00107 do \ 00108 { \ 00109 std::ostringstream err_ostr; \ 00110 err_ostr << err_msg; \ 00111 return moab::MBError( __LINE__, __func__, __FILENAME__, __MBSDIR__, err_code, err_ostr.str().c_str(), \ 00112 moab::MB_ERROR_TYPE_NEW_GLOBAL ); \ 00113 } while( false ) 00114 00115 //! Similar to MB_SET_ERR_RET except that the error is considered globally fatal 00116 #define MB_SET_GLB_ERR_RET( err_msg ) \ 00117 do \ 00118 { \ 00119 std::ostringstream err_ostr; \ 00120 err_ostr << ( err_msg ); \ 00121 moab::MBError( __LINE__, __func__, __FILENAME__, __MBSDIR__, moab::MB_FAILURE, err_ostr.str().c_str(), \ 00122 moab::MB_ERROR_TYPE_NEW_GLOBAL ); \ 00123 return; \ 00124 } while( false ) 00125 00126 //! Similar to MB_SET_ERR_RET_VAL except that the error is considered globally fatal 00127 #define MB_SET_GLB_ERR_RET_VAL( err_msg, ret_val ) \ 00128 do \ 00129 { \ 00130 std::ostringstream err_ostr; \ 00131 err_ostr << ( err_msg ); \ 00132 moab::MBError( __LINE__, __func__, __FILENAME__, __MBSDIR__, moab::MB_FAILURE, err_ostr.str().c_str(), \ 00133 moab::MB_ERROR_TYPE_NEW_GLOBAL ); \ 00134 return ret_val; \ 00135 } while( false ) 00136 00137 //! Similar to MB_SET_ERR_CONT except that the error is considered globally fatal 00138 #define MB_SET_GLB_ERR_CONT( err_msg ) \ 00139 do \ 00140 { \ 00141 std::ostringstream err_ostr; \ 00142 err_ostr << ( err_msg ); \ 00143 moab::MBError( __LINE__, __func__, __FILENAME__, __MBSDIR__, moab::MB_FAILURE, err_ostr.str().c_str(), \ 00144 moab::MB_ERROR_TYPE_NEW_GLOBAL ); \ 00145 } while( false ) 00146 00147 //! Check error code, if not MB_SUCCESS, call the error handler and return the given error code 00148 //! Used in functions which return ErrorCode 00149 #define MB_CHK_ERR( err_code ) \ 00150 do \ 00151 { \ 00152 if( moab::MB_SUCCESS != ( err_code ) ) \ 00153 return moab::MBError( __LINE__, __func__, __FILENAME__, __MBSDIR__, err_code, "", \ 00154 moab::MB_ERROR_TYPE_EXISTING ); \ 00155 } while( false ) 00156 00157 //! Check error code, if not MB_SUCCESS, call the error handler and return 00158 //! Used in functions which return void types (or have no return types at all, e.g. constructors) 00159 #define MB_CHK_ERR_RET( err_code ) \ 00160 do \ 00161 { \ 00162 if( moab::MB_SUCCESS != ( err_code ) ) \ 00163 { \ 00164 moab::MBError( __LINE__, __func__, __FILENAME__, __MBSDIR__, err_code, "", moab::MB_ERROR_TYPE_EXISTING ); \ 00165 return; \ 00166 } \ 00167 } while( false ) 00168 00169 //! Check error code, if not MB_SUCCESS, call the error handler and return the given value 00170 //! Used in functions which return any data type 00171 #define MB_CHK_ERR_RET_VAL( err_code, ret_val ) \ 00172 do \ 00173 { \ 00174 if( moab::MB_SUCCESS != ( err_code ) ) \ 00175 { \ 00176 moab::MBError( __LINE__, __func__, __FILENAME__, __MBSDIR__, err_code, "", moab::MB_ERROR_TYPE_EXISTING ); \ 00177 return ret_val; \ 00178 } \ 00179 } while( false ) 00180 00181 //! Check error code, if not MB_SUCCESS, call the error handler and continue 00182 //! Used in functions which return any data type 00183 #define MB_CHK_ERR_CONT( err_code ) \ 00184 do \ 00185 { \ 00186 if( moab::MB_SUCCESS != ( err_code ) ) \ 00187 { \ 00188 moab::MBError( __LINE__, __func__, __FILENAME__, __MBSDIR__, err_code, "", moab::MB_ERROR_TYPE_EXISTING ); \ 00189 } \ 00190 } while( false ) 00191 00192 //! Check error code, if not MB_SUCCESS, set a new error with the given error message and return the 00193 //! given error code Used in functions which return ErrorCode 00194 #define MB_CHK_SET_ERR( err_code, err_msg ) \ 00195 do \ 00196 { \ 00197 if( moab::MB_SUCCESS != ( err_code ) ) MB_SET_ERR( err_code, err_msg ); \ 00198 } while( false ) 00199 00200 //! Check error code, if not MB_SUCCESS, set a new error with the given error message and return 00201 //! Used in functions which return void types (or have no return types at all, e.g. constructors) 00202 #define MB_CHK_SET_ERR_RET( err_code, err_msg ) \ 00203 do \ 00204 { \ 00205 if( moab::MB_SUCCESS != ( err_code ) ) MB_SET_ERR_RET( err_msg ); \ 00206 } while( false ) 00207 00208 //! Check error code, if not MB_SUCCESS, set a new error with the given error message and return the 00209 //! given value Used in functions which return any data type 00210 #define MB_CHK_SET_ERR_RET_VAL( err_code, err_msg, ret_val ) \ 00211 do \ 00212 { \ 00213 if( moab::MB_SUCCESS != ( err_code ) ) MB_SET_ERR_RET_VAL( err_msg, ret_val ); \ 00214 } while( false ) 00215 00216 //! Check error code, if not MB_SUCCESS, set a new error with the given error message and continue 00217 //! Used in functions which return any data type 00218 #define MB_CHK_SET_ERR_CONT( err_code, err_msg ) \ 00219 do \ 00220 { \ 00221 if( moab::MB_SUCCESS != ( err_code ) ) MB_SET_ERR_CONT( err_msg ); \ 00222 } while( false ) 00223 00224 #endif