00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00014
00015
00016 #ifndef __defined_libdai_exceptions_h
00017 #define __defined_libdai_exceptions_h
00018
00019
00020 #include <exception>
00021 #include <stdexcept>
00022 #include <string>
00023 #include <iostream>
00024
00025
00027 #define DAI_QUOTE(x) #x
00028
00030 #define DAI_TOSTRING(x) DAI_QUOTE(x)
00031
00033
00042 #define DAI_THROW(cod) throw dai::Exception(dai::Exception::cod, std::string(__FILE__ ", line " DAI_TOSTRING(__LINE__)))
00043
00045
00053 #define DAI_THROWE(cod,msg) throw dai::Exception(dai::Exception::cod, std::string(__FILE__ ", line " DAI_TOSTRING(__LINE__)), msg)
00054
00056 #define DAI_ASSERT(condition) ((condition) ? ((void)0) : DAI_THROWE(ASSERTION_FAILED, std::string("Assertion \"" #condition "\" failed")))
00057
00058
00059 #ifdef DAI_DEBUG
00061 #define DAI_DEBASSERT(x) do {DAI_ASSERT(x);} while(0)
00062 #else
00063 #define DAI_DEBASSERT(x) do {} while(0)
00064 #endif
00065
00066
00067 namespace dai {
00068
00069
00071
00075 class Exception : public std::runtime_error {
00076 public:
00078 enum Code {NOT_IMPLEMENTED,
00079 ASSERTION_FAILED,
00080 IMPOSSIBLE_TYPECAST,
00081 OBJECT_NOT_FOUND,
00082 BELIEF_NOT_AVAILABLE,
00083 UNKNOWN_ENUM_VALUE,
00084 UNKNOWN_DAI_ALGORITHM,
00085 UNKNOWN_PARAMETER_ESTIMATION_METHOD,
00086 UNKNOWN_PROPERTY_TYPE,
00087 UNKNOWN_PROPERTY,
00088 MALFORMED_PROPERTY,
00089 NOT_ALL_PROPERTIES_SPECIFIED,
00090 INVALID_ALIAS,
00091 CANNOT_READ_FILE,
00092 CANNOT_WRITE_FILE,
00093 INVALID_FACTORGRAPH_FILE,
00094 INVALID_EVIDENCE_FILE,
00095 INVALID_EMALG_FILE,
00096 NOT_NORMALIZABLE,
00097 MULTIPLE_UNDO,
00098 FACTORGRAPH_NOT_CONNECTED,
00099 INTERNAL_ERROR,
00100 RUNTIME_ERROR,
00101 OUT_OF_MEMORY,
00102 NUM_ERRORS};
00103
00105 Exception( Code _code, const std::string& msg="", const std::string& detailedMsg="" ) : std::runtime_error(ErrorStrings[_code] + " [" + msg + "]"), errorcode(_code) {
00106 if( !detailedMsg.empty() )
00107 std::cerr << "EXCEPTION: " << detailedMsg << std::endl;
00108 }
00109
00111 Code code() const { return errorcode; }
00112
00114 const std::string& message( const Code c ) const { return ErrorStrings[c]; }
00115
00116
00117 private:
00119 Code errorcode;
00120
00122 static std::string ErrorStrings[NUM_ERRORS];
00123 };
00124
00125
00126 }
00127
00128
00129 #endif