aGrUM  0.16.0
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/core/types.h>
38 
39 #define GUM_ERROR_IN_EXPR(type, msg) throw(type(msg))
40 
41 #ifdef SWIG
42 # define GUM_ERROR(type, msg) \
43  { \
44  std::ostringstream __error__str; \
45  __error__str << msg; \
46  throw(type(__error__str.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__str; \
58  __error__str << __FILE__ << ":" << __LINE__ << ": " << msg; \
59  throw(type(__error__str.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
69 # define GUM_ERROR(type, msg) \
70  { \
71  std::ostringstream __error__str; \
72  __error__str << msg; \
73  throw(type(gum::__createMsg( \
74  __FILE__, __FUNCTION__, __LINE__, __error__str.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 // 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__str; \
97  __error__str << msg; \
98  throw(gum::SyntaxError(__error__str.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 SWIG
126  const std::string what() const { return "[pyAgrum] " + _type + ": " + _msg; }
127 #else
128  const std::string what() const { return "[pyAgrum] " + _type + " : " + _msg; }
129 #endif
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, "Edge invalid")
517  GUM_MAKE_ERROR(InvalidArc, GraphError, "Arc invalid")
518  GUM_MAKE_ERROR(InvalidNode, GraphError, "Node invalid")
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-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
const std::string errorType() const
Returns the error type.
Definition: exceptions.h:141
std::string _callstack
Definition: exceptions.h:110
Exception : several evidence are incompatible together (proba=0)
Definition: exceptions.h:376
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
The base class for all directed edgesThis class is used as a basis for manipulating all directed edge...
std::string _type
Definition: exceptions.h:109
Base class for all aGrUM&#39;s exceptions.
Definition: exceptions.h:106
Exception(const std::string aMsg="", const std::string aType="Generic error")
The base class for all undirected edges.
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 _msg
Definition: exceptions.h:108