00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _EXCEPTION_HPP_
00031 #define _EXCEPTION_HPP_
00032
00039 #include <string>
00040
00041 #include <cfloat>
00042 #include <climits>
00043 #include <cstdlib>
00044
00046 const unsigned UNSIGNED_UNSET=UINT_MAX;
00048 const int INT_UNSET=INT_MAX;
00050 const double DOUBLE_UNSET=DBL_MAX;
00051
00058 class Exception
00059 {
00060 private:
00061 std::string mMessage;
00062 std::string mShortMessage;
00064 public:
00072 Exception(const std::string& rMessage, const std::string& rFilename, unsigned lineNumber);
00073
00079 std::string GetMessage() const;
00080
00086 std::string GetShortMessage() const;
00087
00097 std::string CheckShortMessage(std::string expected) const;
00098
00108 std::string CheckShortMessageContains(std::string expected) const;
00109 };
00110
00116 #define EXCEPTION(message) throw Exception(message, __FILE__, __LINE__)
00117
00118
00119 #include <boost/preprocessor/stringize.hpp>
00120
00127 #define EXCEPT_IF_NOT(test) \
00128 if (!(test)) EXCEPTION("Assertion tripped: " BOOST_PP_STRINGIZE(test))
00129
00135 #ifdef NDEBUG
00136 #define UNUSED_OPT(var) var=var
00137 #else
00138 #define UNUSED_OPT(var)
00139 #endif
00140
00147 #define EXPECT0(cmd, arg) { \
00148 std::string _arg(arg); \
00149 int ret = cmd(_arg.c_str()); \
00150 if (ret != 0) { \
00151 EXCEPTION("Error executing command: " #cmd "(" + _arg + ")"); \
00152 } }
00153
00160 #define MPIABORTIFNON0(cmd, arg) { \
00161 std::string _arg(arg); \
00162 int ret = cmd(_arg.c_str()); \
00163 if (ret != 0) { \
00164 std::cout << "Error executing command: " #cmd "(" + _arg + ")"; \
00165 MPI_Abort(PETSC_COMM_WORLD, -1); \
00166 } }
00167
00174 #define EXPECTNON0(cmd, arg) { \
00175 std::string _arg = (arg); \
00176 int ret = cmd(_arg.c_str()); \
00177 if (ret == 0) { \
00178 EXCEPTION("Command: " #cmd "(" + _arg + ") succeeded and it shouldn't have"); \
00179 } }
00180
00187 #define IGNORE_RET(cmd, arg) { \
00188 std::string _arg = (arg); \
00189 int ret = cmd(_arg.c_str()); \
00190 ret = ret; \
00191 }
00192
00193 #endif // _EXCEPTION_HPP_