27 #ifndef GUM_EXCEPTIONS_H 28 #define GUM_EXCEPTIONS_H 36 #include <agrum/tools/core/types.h> 38 #define GUM_ERROR_IN_EXPR(type, msg) throw(type(msg)) 41 # define GUM_ERROR(type, msg) 43 std::ostringstream error_stream; 45 throw(type(error_stream.str())); 47 # define GUM_SHOWERROR(e) 48 { std::cout << std::endl << (e).errorType() << " : " << (e).errorContent() << std::endl; } 50 # ifndef GUM_DEBUG_MODE 51 # define GUM_ERROR(type, msg) 53 std::ostringstream error_stream; 54 error_stream << __FILE__ << ":" << __LINE__ << ": " << msg; 55 throw(type(error_stream.str())); 57 # define GUM_SHOWERROR(e) 59 std::cout << std::endl 60 << __FILE__ << ":" << __LINE__ << " " << (e).errorType() << " from " 62 << (e).errorContent() << std::endl; 65 # define GUM_ERROR(type, msg) 67 std::ostringstream error_stream; 69 throw(type(gum::_createMsg_(__FILE__, __FUNCTION__, __LINE__, error_stream.str()))); 71 # define GUM_SHOWERROR(e) 73 std::cout << std::endl 74 << __FILE__ << ":" << __LINE__ << " " << (e).errorType() << " from " 76 << (e).errorContent() << std::endl; 77 std::cout << (e).errorCallStack() << std::endl; 82 #define GUM_MAKE_ERROR(TYPE, SUPERCLASS, MSG) 83 class TYPE: public SUPERCLASS { 85 explicit TYPE(const std::string& aMsg, const std::string& aType = MSG) : 86 SUPERCLASS(aMsg, aType){}; 87 TYPE(const TYPE& src) : SUPERCLASS(src){}; 90 #define GUM_SYNTAX_ERROR(msg, line, column) 92 std::ostringstream error_stream; 94 throw(gum::SyntaxError(error_stream.str(), line, column)); 106 std::string callstack_;
113 explicit Exception(std::string aMsg =
"", std::string aType =
"Generic error");
115 Exception(
const Exception& e);
117 ~Exception() =
default;
121 std::string what()
const {
return "[pyAgrum] " + type_ +
": " + msg_; }
123 std::string what()
const {
return type_ +
" : " + msg_; }
130 std::string errorContent()
const {
return msg_; }
136 std::string errorType()
const {
return type_; }
142 std::string errorCallStack()
const {
return callstack_; }
165 class UndefinedIteratorValue;
172 class UndefinedIteratorKey;
186 class UndefinedElement;
202 class InvalidArgumentsNumber;
210 class InvalidArgument;
224 class FormatNotFound;
231 class OperationNotAllowed;
259 class DuplicateElement;
266 class DuplicateLabel;
323 class DefaultInLabel;
330 class InvalidDirectedCycle;
345 class IncompatibleEvidence;
359 class FactoryInvalidState;
373 class WrongClassElement;
394 class IncompatibleScoreApriori;
402 class PossiblyIncompatibleScoreApriori;
416 class MissingVariableInDatabase;
423 class UnknownLabelInDatabase;
430 class MissingValueInDatabase;
446 class NotImplementedYet;
449 #ifndef DOXYGEN_SHOULD_SKIP_THIS 450 const std::string _createMsg_(
const std::string& filename,
451 const std::string& function,
453 const std::string& msg);
455 GUM_MAKE_ERROR(NotImplementedYet, Exception,
"Not implemented yet")
457 GUM_MAKE_ERROR(UndefinedIteratorValue, IteratorError,
"Undefined iterator")
458 GUM_MAKE_ERROR(UndefinedIteratorKey, IteratorError,
"Undefined iterator's key")
463 GUM_MAKE_ERROR(InvalidArgumentsNumber, ArgumentError,
"Invalid argument number")
464 GUM_MAKE_ERROR(InvalidArgument, ArgumentError,
"Invalid argument")
467 GUM_MAKE_ERROR(OperationNotAllowed, Exception,
"Operation not allowed")
470 GUM_MAKE_ERROR(DuplicateElement, ArgumentError,
"Duplicate element")
480 GUM_MAKE_ERROR(InvalidDirectedCycle, GraphError,
"Directed cycle detected")
484 "Several evidence/CPT are incompatible together (proba=0)")
486 GUM_MAKE_ERROR(FactoryInvalidState, FactoryError,
"Invalid state error")
488 GUM_MAKE_ERROR(WrongClassElement, FactoryError,
"Wrong ClassElement")
489 GUM_MAKE_ERROR(PRMTypeError, FactoryError,
"Wrong subtype or subclass")
491 GUM_MAKE_ERROR(IncompatibleScoreApriori, LearningError,
"Incompatible (maybe implicit) priors")
494 "Possible incompatibility between score and prior")
496 GUM_MAKE_ERROR(MissingVariableInDatabase, LearningError,
"Missing variable name in database")
497 GUM_MAKE_ERROR(MissingValueInDatabase, LearningError,
"The database contains some missing values")
498 GUM_MAKE_ERROR(UnknownLabelInDatabase, LearningError,
"Unknown label found in database")
500 class SyntaxError:
public IOError {
506 SyntaxError(
const std::string& aMsg,
509 const std::string& aType =
"Syntax Error") :
510 IOError(aMsg, aType),
511 noLine_(nol), noCol_(noc){
515 Size col()
const {
return noCol_; };
516 Size line()
const {
return noLine_; };
#define GUM_MAKE_ERROR(TYPE, SUPERCLASS, MSG)