aGrUM  0.14.2
exceptions.h
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN and Christophe GONZALES *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
25 #ifndef GUM_EXCEPTIONS_H
26 #define GUM_EXCEPTIONS_H
27 // WARNING : Do not include this file directly : instead include
28 // <agrum/config.h>
29 
30 #include <iomanip>
31 #include <iostream>
32 #include <string>
33 
34 #include <agrum/core/types.h>
35 
36 #define GUM_ERROR_IN_EXPR(type, msg) throw(type(msg))
37 
38 #ifdef SWIG
39 # define GUM_ERROR(type, msg) \
40  { \
41  std::ostringstream __error__str; \
42  __error__str << msg; \
43  throw(type(__error__str.str())); \
44  }
45 # define GUM_SHOWERROR(e) \
46  { \
47  std::cout << std::endl \
48  << (e).errorType() << " : " << (e).errorContent() << std::endl; \
49  }
50 #else
51 # ifndef GUM_DEBUG_MODE
52 # define GUM_ERROR(type, msg) \
53  { \
54  std::ostringstream __error__str; \
55  __error__str << __FILE__ << ":" << __LINE__ << ": " << msg; \
56  throw(type(__error__str.str())); \
57  }
58 # define GUM_SHOWERROR(e) \
59  { \
60  std::cout << std::endl \
61  << __FILE__ << ":" << __LINE__ << " " << (e).errorType() \
62  << " from " << std::endl \
63  << (e).errorContent() << std::endl; \
64  }
65 # else
66 # define GUM_ERROR(type, msg) \
67  { \
68  std::ostringstream __error__str; \
69  __error__str << msg; \
70  throw(type(gum::__createMsg( \
71  __FILE__, __FUNCTION__, __LINE__, __error__str.str()))); \
72  }
73 # define GUM_SHOWERROR(e) \
74  { \
75  std::cout << std::endl \
76  << __FILE__ << ":" << __LINE__ << " " << (e).errorType() \
77  << " from " << std::endl \
78  << (e).errorContent() << std::endl; \
79  std::cout << (e).errorCallStack() << std::endl; \
80  }
81 # endif // GUM_DEBUG_MODE
82 #endif // SWIG
83 
84 #define GUM_MAKE_ERROR(TYPE, SUPERCLASS, MSG) \
85  class TYPE : public SUPERCLASS { \
86  public: \
87  TYPE(std::string aMsg, std::string aType = MSG) : SUPERCLASS(aMsg, aType){}; \
88  TYPE(const TYPE& src) : SUPERCLASS(src){}; \
89  };
90 
91 #define GUM_SYNTAX_ERROR(msg, line, column) \
92  { \
93  std::ostringstream __error__str; \
94  __error__str << msg; \
95  throw(gum::SyntaxError(__error__str.str(), line, column)); \
96  }
97 
98 namespace gum {
99 
103  class Exception {
104  protected:
105  std::string _msg;
106  std::string _type;
107  std::string _callstack;
108 
109  public:
110  // ====================================================================
112  // ====================================================================
114  Exception(const std::string aMsg = "",
115  const std::string aType = "Generic error");
116 
117  Exception(const Exception& e);
118 
120 
122 #ifdef SWIG
123  const std::string what() const { return "[pyAgrum] " + _type + ": " + _msg; }
124 #else
125  const std::string what() const { return "[pyAgrum] " + _type + " : " + _msg; }
126 #endif
127 
132  const std::string errorContent() const { return _msg; }
133 
138  const std::string errorType() const { return _type; }
139 
144  const std::string errorCallStack() const { return _callstack; }
145  };
146 
152  class IdError;
153 
159  class FatalError;
160 
167 
174 
180  class NullElement;
181 
188 
194  class SizeError;
195 
201  class EmptySet;
202 
210 
218 
224  class IOError;
225 
232 
239 
245  class NotFound;
246 
253 
259  class OutOfBounds;
260 
267 
274 
281 
288 
290 
295  class GraphError;
296 
302  class NoNeighbour;
303 
309  class NoParent;
310 
316  class NoChild;
317 
323  class InvalidEdge;
324 
330  class InvalidArc;
331 
337  class InvalidNode;
338 
344  class EmptyBSTree;
345 
352 
359 
361 
366  class CPTError;
367 
373  class CPTNoSumTo1;
374 
380 
387 
394 
400  class WrongType;
401 
408 
414  class TypeError;
415 
422 
429 
437 
444 
451 
458 
465 
466 
473  class SyntaxError;
474 
480  class NotImplementedYet;
481 
482 
483 #ifndef DOXYGEN_SHOULD_SKIP_THIS
484  const std::string __createMsg(const std::string& filename,
485  const std::string& function,
486  const int line,
487  const std::string& msg);
488  GUM_MAKE_ERROR(IdError, Exception, "ID error")
489  GUM_MAKE_ERROR(FatalError, Exception, "Fatal error")
490  GUM_MAKE_ERROR(NotImplementedYet, Exception, "Not implemented yet")
491  GUM_MAKE_ERROR(UndefinedIteratorValue, Exception, "Undefined iterator")
492  GUM_MAKE_ERROR(UndefinedIteratorKey, Exception, "Undefined iterator's key")
493  GUM_MAKE_ERROR(NullElement, Exception, "Null element")
494  GUM_MAKE_ERROR(UndefinedElement, Exception, "Undefined element")
495  GUM_MAKE_ERROR(SizeError, Exception, "incorrect size")
496  GUM_MAKE_ERROR(EmptySet, Exception, "Empty set")
497  GUM_MAKE_ERROR(InvalidArgumentsNumber, Exception, "Invalid argument number")
498  GUM_MAKE_ERROR(InvalidArgument, Exception, "Invalid argument")
499  GUM_MAKE_ERROR(IOError, Exception, "I/O Error")
500  GUM_MAKE_ERROR(FormatNotFound, IOError, "Format not found")
501  GUM_MAKE_ERROR(OperationNotAllowed, Exception, "Operation not allowed")
502  GUM_MAKE_ERROR(NotFound, Exception, "Object not found")
503  GUM_MAKE_ERROR(ReferenceError, Exception, "Reference error")
504  GUM_MAKE_ERROR(OutOfBounds, ReferenceError, "Out of bound error")
505  GUM_MAKE_ERROR(OutOfLowerBound, OutOfBounds, "Out of lower bound error")
506  GUM_MAKE_ERROR(OutOfUpperBound, OutOfBounds, "Out of upper bound error")
507  GUM_MAKE_ERROR(DuplicateElement, ReferenceError, "Duplicate element")
508  GUM_MAKE_ERROR(DuplicateLabel, ReferenceError, "Duplicate label")
509  GUM_MAKE_ERROR(GraphError, Exception, "Graph error")
510  GUM_MAKE_ERROR(NoNeighbour, GraphError, "No neighbour found")
511  GUM_MAKE_ERROR(NoParent, GraphError, "No parent found")
512  GUM_MAKE_ERROR(NoChild, GraphError, "No child found")
513  GUM_MAKE_ERROR(InvalidEdge, GraphError, "Edge invalid")
514  GUM_MAKE_ERROR(InvalidArc, GraphError, "Arc invalid")
515  GUM_MAKE_ERROR(InvalidNode, GraphError, "Node invalid")
516  GUM_MAKE_ERROR(EmptyBSTree, GraphError, "Empty binary search tree")
517  GUM_MAKE_ERROR(DefaultInLabel, GraphError, "Error on label")
518  GUM_MAKE_ERROR(InvalidDirectedCycle, GraphError, "Directed cycle detected")
519  GUM_MAKE_ERROR(CPTError, Exception, "CPT error")
520  GUM_MAKE_ERROR(CPTNoSumTo1, CPTError, "CPT does not sum to 1")
522  Exception,
523  "several evidence/CPT are incompatible together (proba=0)")
524  GUM_MAKE_ERROR(FactoryError, Exception, "factory error")
525  GUM_MAKE_ERROR(FactoryInvalidState, FactoryError, "invalid state error")
526  GUM_MAKE_ERROR(WrongType, FactoryError, "wrong type for this operation")
527  GUM_MAKE_ERROR(WrongClassElement, FactoryError, "Wrong ClassElement")
528  GUM_MAKE_ERROR(TypeError, FactoryError, "Wrong subtype or subclass")
529  GUM_MAKE_ERROR(LearningError, Exception, "Factory error")
531  LearningError,
532  "Incompatbile (maybe implicit) priors")
534  LearningError,
535  "Possible incompatibilty between score and prior")
536  GUM_MAKE_ERROR(DatabaseError, LearningError, "Database error")
538  LearningError,
539  "Missing variable name in database")
541  LearningError,
542  "The database contains some missing values")
544  LearningError,
545  "Unknown label found in database")
546 
547  class SyntaxError : public IOError {
548  protected:
549  Size _noLine;
550  Size _noCol;
551 
552  public:
553  SyntaxError(const std::string& aMsg,
554  Size nol,
555  Size noc,
556  std::string aType = "Syntax Error") :
557  IOError(aMsg, aType),
558  _noLine(nol), _noCol(noc){
559 
560  };
561 
562  Size col() const { return _noCol; };
563  Size line() const { return _noLine; };
564  };
565 #endif // DOXYGEN_SHOULD_SKIP_THIS
566 } /* namespace gum */
567 
568 #endif /* GUM_EXCEPTIONS_H */
#define GUM_MAKE_ERROR(TYPE, SUPERCLASS, MSG)
Definition: exceptions.h:84
const std::string errorCallStack() const
Returns the error call stack.
Definition: exceptions.h:144
Provides basic types used in aGrUM.
const std::string errorType() const
Returns the error type.
Definition: exceptions.h:138
std::string _callstack
Definition: exceptions.h:107
Exception : several evidence are incompatible together (proba=0)
Definition: exceptions.h:373
gum is the global namespace for all aGrUM entities
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:106
Base class for all aGrUM&#39;s exceptions.
Definition: exceptions.h:103
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:125
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
const std::string errorContent() const
Returns the message content.
Definition: exceptions.h:132
std::string _msg
Definition: exceptions.h:105