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
00038 #include <string>
00039 #include <iostream>
00040 #include <cfloat>
00041 #include <climits>
00042 #include <cstdlib>
00043
00045 const unsigned UNSIGNED_UNSET=UINT_MAX;
00047 const int INT_UNSET=INT_MAX;
00049 const double DOUBLE_UNSET=DBL_MAX;
00050
00057 class Exception
00058 {
00059 private:
00060 std::string mMessage;
00061 std::string mShortMessage;
00063 public:
00071 Exception(const std::string& rMessage, const std::string& rFilename, unsigned lineNumber);
00072
00078 std::string GetMessage() const;
00079
00085 std::string GetShortMessage() const;
00086
00096 std::string CheckShortMessage(std::string expected) const;
00097
00107 std::string CheckShortMessageContains(std::string expected) const;
00108 };
00109
00115 #define EXCEPTION(message) throw Exception(message, __FILE__, __LINE__)
00116
00117
00118 #include <boost/preprocessor/stringize.hpp>
00119
00126 #define EXCEPT_IF_NOT(test) \
00127 if (!(test)) EXCEPTION("Assertion tripped: " BOOST_PP_STRINGIZE(test))
00128
00134 #ifdef NDEBUG
00135 #define UNUSED_OPT(var) var=var
00136 #else
00137 #define UNUSED_OPT(var)
00138 #endif
00139
00152 #define EXPECT0(cmd, arg) { \
00153 std::string _arg(arg); \
00154 int ret = cmd(_arg.c_str()); \
00155 if (ret != 0) { \
00156 EXCEPTION("Error executing command: " #cmd "(" + _arg + ")"); \
00157 } }
00158
00159
00166 #define MPI_ABORT_IF_NON0_WITH_MSG(retcode, msg) \
00167 if (retcode != 0) { \
00168 std::cerr << msg << std::endl << std::flush; \
00169 MPI_Abort(PETSC_COMM_WORLD, -1); \
00170 }
00171
00178 #define MPIABORTIFNON0(cmd, arg) { \
00179 std::string _arg(arg); \
00180 int ret = cmd(_arg.c_str()); \
00181 MPI_ABORT_IF_NON0_WITH_MSG(ret, "Error executing command: " #cmd "(" + _arg + ")") \
00182 }
00183
00190 #define EXPECTNON0(cmd, arg) { \
00191 std::string _arg = (arg); \
00192 int ret = cmd(_arg.c_str()); \
00193 if (ret == 0) { \
00194 EXCEPTION("Command: " #cmd "(" + _arg + ") succeeded and it shouldn't have"); \
00195 } }
00196
00203 #define IGNORE_RET(cmd, arg) { \
00204 std::string _arg = (arg); \
00205 int ret = cmd(_arg.c_str()); \
00206 ret = ret; \
00207 }
00208
00209 #endif // _EXCEPTION_HPP_