13 #ifndef __defined_libdai_exceptions_h
14 #define __defined_libdai_exceptions_h
24 #define DAI_QUOTE(x) #x
27 #define DAI_TOSTRING(x) DAI_QUOTE(x)
39 #if defined __GNUG__ // GNU C++
40 #define FUNCTION_NAME __PRETTY_FUNCTION__
41 #elif defined _MSC_VER // Visual Studio
42 #define FUNCTION_NAME __FUNCTION__
43 #else // other compilers
44 #define FUNCTION_NAME __func__
46 #define DAI_THROW(cod) throw dai::Exception(dai::Exception::cod, __FILE__, FUNCTION_NAME, DAI_TOSTRING(__LINE__), "")
57 #define DAI_THROWE(cod,msg) throw dai::Exception(dai::Exception::cod, __FILE__, FUNCTION_NAME, DAI_TOSTRING(__LINE__), msg)
60 #define DAI_ASSERT(condition) ((condition) ? ((void)0) : DAI_THROWE(ASSERTION_FAILED, std::string("Assertion \"" #condition "\" failed")))
64 #define DAI_DEBASSERT(x) do {DAI_ASSERT(x);} while(0)
67 #define DAI_DEBASSERT(x) do {} while(0)
82 enum Code {NOT_IMPLEMENTED,
88 UNKNOWN_DAI_ALGORITHM,
89 UNKNOWN_PARAMETER_ESTIMATION_METHOD,
90 UNKNOWN_PROPERTY_TYPE,
93 NOT_ALL_PROPERTIES_SPECIFIED,
97 INVALID_FACTORGRAPH_FILE,
98 INVALID_EVIDENCE_FILE,
102 FACTORGRAPH_NOT_CONNECTED,
109 Exception(
Code code,
const char *filename,
const char *
function,
const char *line,
const std::string& detailedMsg ) :
110 std::runtime_error(
ErrorStrings[code] + (detailedMsg.empty() ?
"" : (
": " + detailedMsg)) +
" [File " + filename +
", line " + line +
", function: " + function +
"]"),
Code getCode() const
Returns error code of this exception.
Definition: exceptions.h:117
Code code() const
Returns error code of this exception.
Definition: exceptions.h:122
static std::string ErrorStrings[NUM_ERRORS]
Error messages corresponding to the exceptions enumerated above.
Definition: exceptions.h:159
~Exception()
Destructor.
Definition: exceptions.h:114
Error handling in libDAI is done by throwing an instance of the Exception class.
Definition: exceptions.h:79
std::string _detailedMsg
Contains the detailed message of this exception, if any.
Definition: exceptions.h:147
Exception(Code code, const char *filename, const char *function, const char *line, const std::string &detailedMsg)
Constructor.
Definition: exceptions.h:109
const std::string & message(const Code c) const
Returns error message corresponding to an error code.
Definition: exceptions.h:140
const std::string & getFilename() const
Returns filename where this exception was thrown.
Definition: exceptions.h:131
std::string _line
Contains the line number where this exception was thrown.
Definition: exceptions.h:156
Code _errorcode
Contains the error code of this exception.
Definition: exceptions.h:144
const std::string & getDetailedMsg() const
Returns detailed error message of this exception.
Definition: exceptions.h:128
std::string _filename
Contains the filename where this exception was thrown.
Definition: exceptions.h:150
const std::string & getFunction() const
Returns function name in which this exception was thrown.
Definition: exceptions.h:134
const std::string & getLine() const
Returns line number where this exception was thrown.
Definition: exceptions.h:137
Namespace for libDAI.
Definition: alldai.cpp:16
std::string _function
Contains the function name in which this exception was thrown.
Definition: exceptions.h:153
Code
Enumeration of exceptions used in libDAI.
Definition: exceptions.h:82
const std::string & getMsg() const
Returns short error message of this exception.
Definition: exceptions.h:125