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) 49 std::cout << std::endl 50 << (e).errorType() << " : " << (e).errorContent() << std::endl; 53 # ifndef GUM_DEBUG_MODE 54 # define GUM_ERROR(type, msg) 56 std::ostringstream error_stream; 57 error_stream << __FILE__ << ":" << __LINE__ << ": " << msg; 58 throw(type(error_stream.str())); 60 # define GUM_SHOWERROR(e) 62 std::cout << std::endl 63 << __FILE__ << ":" << __LINE__ << " " << (e).errorType() 64 << " from " << std::endl 65 << (e).errorContent() << std::endl; 68 # define GUM_ERROR(type, msg) 70 std::ostringstream error_stream; 72 throw(type(gum::createMsg__(__FILE__, 75 error_stream.str()))); 77 # define GUM_SHOWERROR(e) 79 std::cout << std::endl 80 << __FILE__ << ":" << __LINE__ << " " << (e).errorType() 81 << " from " << std::endl 82 << (e).errorContent() << std::endl; 83 std::cout << (e).errorCallStack() << std::endl; 88 #define GUM_MAKE_ERROR(TYPE, SUPERCLASS, MSG) 89 class TYPE: public SUPERCLASS { 91 explicit TYPE(const std::string& aMsg, const std::string& aType = MSG) : 92 SUPERCLASS(aMsg, aType){}; 93 TYPE(const TYPE& src) : SUPERCLASS(src){}; 96 #define GUM_SYNTAX_ERROR(msg, line, column) 98 std::ostringstream error_stream; 100 throw(gum::SyntaxError(error_stream.str(), line, column)); 112 std::string callstack_;
119 explicit Exception(std::string aMsg =
"", std::string aType =
"Generic error");
121 Exception(
const Exception& e);
123 ~Exception() =
default;
127 std::string what()
const {
return "[pyAgrum] " + type_ +
": " + msg_; }
129 std::string what()
const {
return type_ +
" : " + msg_; }
136 std::string errorContent()
const {
return msg_; }
142 std::string errorType()
const {
return type_; }
148 std::string errorCallStack()
const {
return callstack_; }
170 class UndefinedIteratorValue;
177 class UndefinedIteratorKey;
191 class UndefinedElement;
213 class InvalidArgumentsNumber;
221 class InvalidArgument;
235 class FormatNotFound;
242 class OperationNotAllowed;
256 class ReferenceError;
270 class OutOfLowerBound;
277 class OutOfUpperBound;
284 class DuplicateElement;
291 class DuplicateLabel;
355 class DefaultInLabel;
362 class InvalidDirectedCycle;
383 class IncompatibleEvidence;
397 class FactoryInvalidState;
411 class WrongClassElement;
432 class IncompatibleScoreApriori;
440 class PossiblyIncompatibleScoreApriori;
454 class MissingVariableInDatabase;
461 class UnknownLabelInDatabase;
468 class MissingValueInDatabase;
484 class NotImplementedYet;
487 #ifndef DOXYGEN_SHOULD_SKIP_THIS 488 const std::string createMsg__(
const std::string& filename,
489 const std::string& function,
491 const std::string& msg);
494 GUM_MAKE_ERROR(NotImplementedYet, Exception,
"Not implemented yet")
495 GUM_MAKE_ERROR(UndefinedIteratorValue, Exception,
"Undefined iterator")
496 GUM_MAKE_ERROR(UndefinedIteratorKey, Exception,
"Undefined iterator's key")
501 GUM_MAKE_ERROR(InvalidArgumentsNumber, Exception,
"Invalid argument number")
505 GUM_MAKE_ERROR(OperationNotAllowed, Exception,
"Operation not allowed")
509 GUM_MAKE_ERROR(OutOfLowerBound, OutOfBounds,
"Out of lower bound error")
510 GUM_MAKE_ERROR(OutOfUpperBound, OutOfBounds,
"Out of upper bound error")
511 GUM_MAKE_ERROR(DuplicateElement, ReferenceError,
"Duplicate element")
520 GUM_MAKE_ERROR(EmptyBSTree, GraphError,
"Empty binary search tree")
522 GUM_MAKE_ERROR(InvalidDirectedCycle, GraphError,
"Directed cycle detected")
527 "Several evidence/CPT are incompatible together (proba=0)")
529 GUM_MAKE_ERROR(FactoryInvalidState, FactoryError,
"Invalid state error")
531 GUM_MAKE_ERROR(WrongClassElement, FactoryError,
"Wrong ClassElement")
532 GUM_MAKE_ERROR(PRMTypeError, FactoryError,
"Wrong subtype or subclass")
536 "Incompatible (maybe implicit) priors")
539 "Possible incompatibility between score and prior")
543 "Missing variable name in database")
546 "The database contains some missing values")
549 "Unknown label found in database")
551 class SyntaxError:
public IOError {
557 SyntaxError(
const std::string& aMsg,
560 const std::string& aType =
"Syntax Error") :
561 IOError(aMsg, aType),
562 noLine_(nol), noCol_(noc){
566 Size col()
const {
return noCol_; };
567 Size line()
const {
return noLine_; };
#define GUM_MAKE_ERROR(TYPE, SUPERCLASS, MSG)