exception-abstract.h
Go to the documentation of this file.
1 // -*- mode: c++ -*-
2 // Copyright 2010, Fran├žois Bleibel, Thomas Moulard, Olivier Stasse,
3 // JRL, CNRS/AIST.
4 //
5 
6 #ifndef DYNAMIC_GRAPH_EXCEPTION_ABSTRACT_H
7 #define DYNAMIC_GRAPH_EXCEPTION_ABSTRACT_H
9 
10 #include <dynamic-graph/fwd.hh>
11 #include <string>
12 
13 // Uncomment this macros to have lines parameter on the throw display
14 // #define DYNAMIC-GRAPH_EXCEPTION_PASSING_PARAM
15 
16 #define DG_RETHROW \
17  (const ::dynamicgraph::ExceptionAbstract &err) { throw err; }
18 
19 #ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM
20 #define DG_THROW \
21  throw ::dynamicgraph::ExceptionAbstract::Param(__LINE__, __FUNCTION__, \
22  __FILE__) +
23 #else
24 #define DG_THROW throw
25 #endif // DYNAMICGRAPH_EXCEPTION_PASSING_PARAM
26 
27 namespace dynamicgraph {
31 class DYNAMIC_GRAPH_DLLAPI ExceptionAbstract : public std::exception {
32  public:
36  class Param {
37  public:
38  static const int BUFFER_SIZE = 80;
39 
40  Param(const int &_line, const char *_function, const char *_file);
42  : functionPTR(),
43  function(),
44  line(),
45  filePTR(),
46  file(),
47  pointersSet(false),
48  set(false) {}
49  Param &initCopy(const Param &p);
50 
51  const char *functionPTR;
52  char function[BUFFER_SIZE];
53  int line;
54  const char *filePTR;
55  char file[BUFFER_SIZE];
57  bool set;
58  };
59 
68  ABSTRACT = 0,
69  SIGNAL = 100,
70  FACTORY = 200,
71  TRACES = 300,
72  TOOLS = 700
73  };
74 
75  static const std::string EXCEPTION_NAME;
76 
77  explicit ExceptionAbstract(const int &code, const std::string &msg = "");
78  virtual ~ExceptionAbstract() throw() {}
79 
80  virtual const std::string &getExceptionName() const { return EXCEPTION_NAME; }
81 
83  int getCode() const;
84 
86  const std::string &getStringMessage() const;
87 
92  const char *getMessage() const;
93 
94  virtual const char *what() const throw() {
95  return getStringMessage().c_str();
96  }
97 
99  DYNAMIC_GRAPH_DLLAPI friend std::ostream &operator<<(
100  std::ostream &os, const ExceptionAbstract &err);
101 
102  protected:
105  int code;
106 
108  std::string message;
109 
110 #ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM
111  mutable Param p;
116 
117  template <class Exc>
118  friend const Exc &operator+(const ExceptionAbstract::Param &p, const Exc &e) {
119  e.p.initCopy(p);
120  return e;
121  }
122 
123  template <class Exc>
124  friend Exc &operator+(const ExceptionAbstract::Param &p, Exc &e) {
125  e.p.initCopy(p);
126  return e;
127  }
128 
129 #endif // DYNAMICGRAPH_EXCEPTION_PASSING_PARAM
130 
131  private:
134 };
135 } // end of namespace dynamicgraph
136 
137 #endif
std::string message
Error message (can be empty).
DYNAMIC_GRAPH_DLLAPI std::ostream & operator<<(std::ostream &os, const dynamicgraph::Entity &ent)
ExceptionEnum
Categories error code.
virtual const std::string & getExceptionName() const
Abstract root class for all dynamic-graph exceptions.
Class owned by exceptions to store error locations.
virtual const char * what() const
static const std::string EXCEPTION_NAME


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Sun Jun 25 2023 02:06:03