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_; }
164 class UndefinedIteratorValue;
171 class UndefinedIteratorKey;
185 class UndefinedElement;
207 class InvalidArgumentsNumber;
215 class InvalidArgument;
229 class FormatNotFound;
236 class OperationNotAllowed;
250 class ReferenceError;
264 class OutOfLowerBound;
271 class OutOfUpperBound;
278 class DuplicateElement;
285 class DuplicateLabel;
349 class DefaultInLabel;
356 class InvalidDirectedCycle;
377 class IncompatibleEvidence;
391 class FactoryInvalidState;
405 class WrongClassElement;
426 class IncompatibleScoreApriori;
434 class PossiblyIncompatibleScoreApriori;
448 class MissingVariableInDatabase;
455 class UnknownLabelInDatabase;
462 class MissingValueInDatabase;
478 class NotImplementedYet;
481 #ifndef DOXYGEN_SHOULD_SKIP_THIS 482 const std::string _createMsg_(
const std::string& filename,
483 const std::string& function,
485 const std::string& msg);
488 GUM_MAKE_ERROR(NotImplementedYet, Exception,
"Not implemented yet")
489 GUM_MAKE_ERROR(UndefinedIteratorValue, Exception,
"Undefined iterator")
490 GUM_MAKE_ERROR(UndefinedIteratorKey, Exception,
"Undefined iterator's key")
495 GUM_MAKE_ERROR(InvalidArgumentsNumber, Exception,
"Invalid argument number")
499 GUM_MAKE_ERROR(OperationNotAllowed, Exception,
"Operation not allowed")
503 GUM_MAKE_ERROR(OutOfLowerBound, OutOfBounds,
"Out of lower bound error")
504 GUM_MAKE_ERROR(OutOfUpperBound, OutOfBounds,
"Out of upper bound error")
505 GUM_MAKE_ERROR(DuplicateElement, ReferenceError,
"Duplicate element")
514 GUM_MAKE_ERROR(EmptyBSTree, GraphError,
"Empty binary search tree")
516 GUM_MAKE_ERROR(InvalidDirectedCycle, GraphError,
"Directed cycle detected")
521 "Several evidence/CPT are incompatible together (proba=0)")
523 GUM_MAKE_ERROR(FactoryInvalidState, FactoryError,
"Invalid state error")
525 GUM_MAKE_ERROR(WrongClassElement, FactoryError,
"Wrong ClassElement")
526 GUM_MAKE_ERROR(PRMTypeError, FactoryError,
"Wrong subtype or subclass")
528 GUM_MAKE_ERROR(IncompatibleScoreApriori, LearningError,
"Incompatible (maybe implicit) priors")
531 "Possible incompatibility between score and prior")
533 GUM_MAKE_ERROR(MissingVariableInDatabase, LearningError,
"Missing variable name in database")
534 GUM_MAKE_ERROR(MissingValueInDatabase, LearningError,
"The database contains some missing values")
535 GUM_MAKE_ERROR(UnknownLabelInDatabase, LearningError,
"Unknown label found in database")
537 class SyntaxError:
public IOError {
543 SyntaxError(
const std::string& aMsg,
546 const std::string& aType =
"Syntax Error") :
547 IOError(aMsg, aType),
548 noLine_(nol), noCol_(noc){
552 Size col()
const {
return noCol_; };
553 Size line()
const {
return noLine_; };
#define GUM_MAKE_ERROR(TYPE, SUPERCLASS, MSG)