aGrUM  0.18.1
a C++ library for (probabilistic) graphical models
exceptions.h
Go to the documentation of this file.
1 
28 #ifndef GUM_EXCEPTIONS_H
29 #define GUM_EXCEPTIONS_H
30 // WARNING : Do not include this file directly : instead include
31 // <agrum/config.h>
32 
33 #include <iomanip>
34 #include <iostream>
35 #include <string>
36 
37 #include <agrum/tools/core/types.h>
38 
39 #define GUM_ERROR_IN_EXPR(type, msg) throw(type(msg))
40 
41 #ifdef GUM_FOR_SWIG
42 # define GUM_ERROR(type, msg) \
43  { \
44  std::ostringstream error_stream; \
45  error_stream << msg; \
46  throw(type(error_stream.str())); \
47  }
48 # define GUM_SHOWERROR(e) \
49  { \
50  std::cout << std::endl \
51  << (e).errorType() << " : " << (e).errorContent() << std::endl; \
52  }
53 #else
54 # ifndef GUM_DEBUG_MODE
55 # define GUM_ERROR(type, msg) \
56  { \
57  std::ostringstream error_stream; \
58  error_stream << __FILE__ << ":" << __LINE__ << ": " << msg; \
59  throw(type(error_stream.str())); \
60  }
61 # define GUM_SHOWERROR(e) \
62  { \
63  std::cout << std::endl \
64  << __FILE__ << ":" << __LINE__ << " " << (e).errorType() \
65  << " from " << std::endl \
66  << (e).errorContent() << std::endl; \
67  }
68 # else // GUM_FOR_SWIG
69 # define GUM_ERROR(type, msg) \
70  { \
71  std::ostringstream error_stream; \
72  error_stream << msg; \
73  throw(type(gum::createMsg__( \
74  __FILE__, __FUNCTION__, __LINE__, error_stream.str()))); \
75  }
76 # define GUM_SHOWERROR(e) \
77  { \
78  std::cout << std::endl \
79  << __FILE__ << ":" << __LINE__ << " " << (e).errorType() \
80  << " from " << std::endl \
81  << (e).errorContent() << std::endl; \
82  std::cout << (e).errorCallStack() << std::endl; \
83  }
84 # endif // GUM_DEBUG_MODE
85 #endif // GUM_FOR_SWIG
86 
87 #define GUM_MAKE_ERROR(TYPE, SUPERCLASS, MSG) \
88  class TYPE: public SUPERCLASS { \
89  public: \
90  TYPE(std::string aMsg, std::string aType = MSG) : SUPERCLASS(aMsg, aType){}; \
91  TYPE(const TYPE& src) : SUPERCLASS(src){}; \
92  };
93 
94 #define GUM_SYNTAX_ERROR(msg, line, column) \
95  { \
96  std::ostringstream error_stream; \
97  error_stream << msg; \
98  throw(gum::SyntaxError(error_stream.str(), line, column)); \
99  }
100 
101 namespace gum {
102 
106  class Exception {
107  protected:
108  std::string msg_;
109  std::string type_;
110  std::string callstack_;
111 
112  public:
113  // ====================================================================
115  // ====================================================================
117  Exception(const std::string aMsg = "",
118  const std::string aType = "Generic error");
119 
120  Exception(const Exception& e);
121 
123 
125 #ifdef GUM_FOR_SWIG
126  const std::string what() const { return "[pyAgrum] " + type_ + ": " + msg_; }
127 #else // GUM_FOR_SWIG
128  const std::string what() const { return type_ + " : " + msg_; }
129 #endif // GUM_FOR_SWIG
130 
135  const std::string errorContent() const { return msg_; }
136 
141  const std::string errorType() const { return type_; }
142 
147  const std::string errorCallStack() const { return callstack_; }
148  };
149 
155  class IdError;
156 
162  class FatalError;
163 
170 
177 
183  class NullElement;
184 
191 
197  class SizeError;
198 
204  class EmptySet;
205 
213 
221 
227  class IOError;
228 
235 
242 
248  class NotFound;
249 
256 
262  class OutOfBounds;
263 
270 
277 
284 
291 
293 
298  class GraphError;
299 
305  class NoNeighbour;
306 
312  class NoParent;
313 
319  class NoChild;
320 
326  class InvalidEdge;
327 
333  class InvalidArc;
334 
340  class InvalidNode;
341 
347  class EmptyBSTree;
348 
355 
362 
364 
369  class CPTError;
370 
376  class CPTNoSumTo1;
377 
383 
390 
397 
403  class WrongType;
404 
411 
417  class TypeError;
418 
425 
432 
440 
447 
454 
461 
468 
469 
476  class SyntaxError;
477 
483  class NotImplementedYet;
484 
485 
486 #ifndef DOXYGEN_SHOULD_SKIP_THIS
487  const std::string createMsg__(const std::string& filename,
488  const std::string& function,
489  const int line,
490  const std::string& msg);
491  GUM_MAKE_ERROR(IdError, Exception, "ID error")
492  GUM_MAKE_ERROR(FatalError, Exception, "Fatal error")
493  GUM_MAKE_ERROR(NotImplementedYet, Exception, "Not implemented yet")
494  GUM_MAKE_ERROR(UndefinedIteratorValue, Exception, "Undefined iterator")
495  GUM_MAKE_ERROR(UndefinedIteratorKey, Exception, "Undefined iterator's key")
496  GUM_MAKE_ERROR(NullElement, Exception, "Null element")
497  GUM_MAKE_ERROR(UndefinedElement, Exception, "Undefined element")
498  GUM_MAKE_ERROR(SizeError, Exception, "incorrect size")
499  GUM_MAKE_ERROR(EmptySet, Exception, "Empty set")
500  GUM_MAKE_ERROR(InvalidArgumentsNumber, Exception, "Invalid argument number")
501  GUM_MAKE_ERROR(InvalidArgument, Exception, "Invalid argument")
502  GUM_MAKE_ERROR(IOError, Exception, "I/O Error")
503  GUM_MAKE_ERROR(FormatNotFound, IOError, "Format not found")
504  GUM_MAKE_ERROR(OperationNotAllowed, Exception, "Operation not allowed")
505  GUM_MAKE_ERROR(NotFound, Exception, "Object not found")
506  GUM_MAKE_ERROR(ReferenceError, Exception, "Reference error")
507  GUM_MAKE_ERROR(OutOfBounds, ReferenceError, "Out of bound error")
508  GUM_MAKE_ERROR(OutOfLowerBound, OutOfBounds, "Out of lower bound error")
509  GUM_MAKE_ERROR(OutOfUpperBound, OutOfBounds, "Out of upper bound error")
510  GUM_MAKE_ERROR(DuplicateElement, ReferenceError, "Duplicate element")
511  GUM_MAKE_ERROR(DuplicateLabel, ReferenceError, "Duplicate label")
512  GUM_MAKE_ERROR(GraphError, Exception, "Graph error")
513  GUM_MAKE_ERROR(NoNeighbour, GraphError, "No neighbour found")
514  GUM_MAKE_ERROR(NoParent, GraphError, "No parent found")
515  GUM_MAKE_ERROR(NoChild, GraphError, "No child found")
516  GUM_MAKE_ERROR(InvalidEdge, GraphError, "Invalid edge")
517  GUM_MAKE_ERROR(InvalidArc, GraphError, "Invalid arc")
518  GUM_MAKE_ERROR(InvalidNode, GraphError, "Invalid node")
519  GUM_MAKE_ERROR(EmptyBSTree, GraphError, "Empty binary search tree")
520  GUM_MAKE_ERROR(DefaultInLabel, GraphError, "Error on label")
521  GUM_MAKE_ERROR(InvalidDirectedCycle, GraphError, "Directed cycle detected")
522  GUM_MAKE_ERROR(CPTError, Exception, "CPT error")
523  GUM_MAKE_ERROR(CPTNoSumTo1, CPTError, "CPT does not sum to 1")
525  Exception,
526  "several evidence/CPT are incompatible together (proba=0)")
527  GUM_MAKE_ERROR(FactoryError, Exception, "factory error")
528  GUM_MAKE_ERROR(FactoryInvalidState, FactoryError, "invalid state error")
529  GUM_MAKE_ERROR(WrongType, FactoryError, "wrong type for this operation")
530  GUM_MAKE_ERROR(WrongClassElement, FactoryError, "Wrong ClassElement")
531  GUM_MAKE_ERROR(TypeError, FactoryError, "Wrong subtype or subclass")
532  GUM_MAKE_ERROR(LearningError, Exception, "Factory error")
534  LearningError,
535  "Incompatbile (maybe implicit) priors")
537  LearningError,
538  "Possible incompatibilty between score and prior")
539  GUM_MAKE_ERROR(DatabaseError, LearningError, "Database error")
541  LearningError,
542  "Missing variable name in database")
544  LearningError,
545  "The database contains some missing values")
547  LearningError,
548  "Unknown label found in database")
549 
550  class SyntaxError: public IOError {
551  protected:
552  Size noLine_;
553  Size noCol_;
554 
555  public:
556  SyntaxError(const std::string& aMsg,
557  Size nol,
558  Size noc,
559  std::string aType = "Syntax Error") :
560  IOError(aMsg, aType),
561  noLine_(nol), noCol_(noc){
562 
563  };
564 
565  Size col() const { return noCol_; };
566  Size line() const { return noLine_; };
567  };
568 #endif // DOXYGEN_SHOULD_SKIP_THIS
569 } /* namespace gum */
570 
571 #endif /* GUM_EXCEPTIONS_H */
#define GUM_MAKE_ERROR(TYPE, SUPERCLASS, MSG)
Definition: exceptions.h:87
const std::string errorCallStack() const
Returns the error call stack.
Definition: exceptions.h:147
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
const std::string errorType() const
Returns the error type.
Definition: exceptions.h:141
std::string type_
Definition: exceptions.h:109
Exception : several evidence are incompatible together (proba=0)
Definition: exceptions.h:376
std::string msg_
Definition: exceptions.h:108
Copyright 2005-2020 Pierre-Henri WUILLEMIN() & Christophe GONZALES() info_at_agrum_dot_org.
Definition: agrum.h:25
Base class for all aGrUM&#39;s exceptions.
Definition: exceptions.h:106
Exception(const std::string aMsg="", const std::string aType="Generic error")
const std::string what() const
Definition: exceptions.h:128
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
const std::string errorContent() const
Returns the message content.
Definition: exceptions.h:135
std::string callstack_
Definition: exceptions.h:110