dynamic_graph_manager
exception-abstract.hh
Go to the documentation of this file.
1 
9 #ifndef ABSTRACT_EXCEPTION_HH
10 #define ABSTRACT_EXCEPTION_HH
11 
12 /* --------------------------------------------------------------------- */
13 /* --- INCLUDE --------------------------------------------------------- */
14 /* --------------------------------------------------------------------- */
15 
16 /* Classes standards. */
17 #include <exception>
18 #include <iostream> /* Classe ostream. */
19 #include <string> /* Classe string. */
20 
21 // Uncomment this macros to have lines parameter on the throw display
22 // #define EXCEPTION_PASSING_PARAM
23 
24 /* --------------------------------------------------------------------- */
25 /* --- CLASS ----------------------------------------------------------- */
26 /* --------------------------------------------------------------------- */
27 
28 namespace dynamic_graph
29 {
33 class ExceptionAbstract : public std::exception
34 {
35 public:
36  enum ExceptionEnum
37  {
38  ABSTRACT = 0,
39  SIGNAL = 100,
40  TASK = 200,
41  FEATURE = 300,
42  FACTORY = 400,
43  DYNAMIC = 500,
44  TRACES = 600,
45  TOOLS = 700,
46  PATTERN_GENERATOR = 800,
47  YAML_CPP_PARSING = 900
48  };
49 
50  static const std::string EXCEPTION_NAME;
51  virtual const std::string& getExceptionName(void) const
52  {
53  return EXCEPTION_NAME;
54  }
55 
56 protected:
59  int code;
60 
62  std::string message;
63 
64 private:
66  ExceptionAbstract(void);
67 
68 public:
69  ExceptionAbstract(const int& code, const std::string& msg = "");
70  virtual ~ExceptionAbstract(void) throw()
71  {
72  }
73 
75  int getCode(void);
76 
78  const std::string& getStringMessage(void);
79 
83  const char* getMessage(void);
84  const char* what() const throw();
85 
87  friend std::ostream& operator<<(std::ostream& os,
88  const ExceptionAbstract& err);
89 
90 #ifdef EXCEPTION_PASSING_PARAM
91 public:
92  class Param
93  {
94  public:
95  static const int BUFFER_SIZE = 80;
96 
97  const char* functionPTR;
98  char function[BUFFER_SIZE];
99  int line;
100  const char* filePTR;
101  char file[BUFFER_SIZE];
102  bool pointersSet, set;
103 
104  public:
105  Param(const int& _line, const char* _function, const char* _file);
106  Param(void) : pointersSet(false), set(false)
107  {
108  }
109  Param& initCopy(const Param& p);
110  };
111 
112 protected:
113  mutable Param p;
114 
115  template <class Exc>
116  friend const Exc& operator+(const ExceptionAbstract::Param& p, const Exc& e)
117  {
118  e.p.initCopy(p);
119  return e;
120  }
121  template <class Exc>
122  friend Exc& operator+(const ExceptionAbstract::Param& p, Exc& e)
123  {
124  e.p.initCopy(p);
125  return e;
126  }
127 #endif //#ifdef EXCEPTION_PASSING_PARAM
128 };
129 
130 #define SOT_RETHROW \
131  (const ExceptionAbstract& err) \
132  { \
133  throw err; \
134  }
135 
136 #ifdef EXCEPTION_PASSING_PARAM
137 #define SOT_THROW \
138  throw ExceptionAbstract::Param(__LINE__, __FUNCTION__, __FILE__) +
139 #else //#ifdef EXCEPTION_PASSING_PARAM
140 #define DG_THROW throw
141 #endif //#ifdef EXCEPTION_PASSING_PARAM
142 
143 } /* namespace dynamic_graph */
144 
145 #endif /* #ifndef ABSTRACT_EXCEPTION_HH */
146 
147 /*
148  * Local variables:
149  * c-basic-offset: 2
150  * End:
151  */
int code
Error code.
Definition: exception-abstract.hh:59
int getCode(void)
Access to the error code.
Definition: exception-abstract.cpp:43
The ExceptionAbstract class.
Definition: exception-abstract.hh:33
this is this package namespace in order to avoid naming conflict
Definition: device.hh:22
std::string message
Error message (can be empty).
Definition: exception-abstract.hh:62
const char * getMessage(void)
Access to the pointer on the array of char related to the error string.
Definition: exception-abstract.cpp:33
const std::string & getStringMessage(void)
Reference access to the error message (can be empty).
Definition: exception-abstract.cpp:38
ExceptionAbstract(void)
forbid the empty constructor (private).