dynamic-graph  4.1.0-8-gdab7-dirty
Dynamic graph library
exception-abstract.h
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
8 #include <string>
9 
10 #include <dynamic-graph/dynamic-graph-api.h>
11 #include <dynamic-graph/fwd.hh>
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);
41  Param()
42  : functionPTR(), function(), line(), filePTR(), file(),
43  pointersSet(false), set(false) {}
44  Param &initCopy(const Param &p);
45 
46  const char *functionPTR;
47  char function[BUFFER_SIZE];
48  int line;
49  const char *filePTR;
50  char file[BUFFER_SIZE];
51  bool pointersSet;
52  bool set;
53  };
54 
63  ABSTRACT = 0,
64  SIGNAL = 100,
65  FACTORY = 200,
66  TRACES = 300,
67  TOOLS = 700
68  };
69 
70  static const std::string EXCEPTION_NAME;
71 
72  explicit ExceptionAbstract(const int &code, const std::string &msg = "");
73  virtual ~ExceptionAbstract() throw() {}
74 
75  virtual const std::string &getExceptionName() const { return EXCEPTION_NAME; }
76 
78  int getCode() const;
79 
81  const std::string &getStringMessage() const;
82 
87  const char *getMessage() const;
88 
89  virtual const char *what() const throw() {
90  return getStringMessage().c_str();
91  }
92 
94  DYNAMIC_GRAPH_DLLAPI friend std::ostream &
95  operator<<(std::ostream &os, const ExceptionAbstract &err);
96 
97 protected:
100  int code;
101 
103  std::string message;
104 
105 #ifdef DYNAMICGRAPH_EXCEPTION_PASSING_PARAM
106  mutable Param p;
111 
112  template <class Exc>
113  friend const Exc &operator+(const ExceptionAbstract::Param &p, const Exc &e) {
114  e.p.initCopy(p);
115  return e;
116  }
117 
118  template <class Exc>
119  friend Exc &operator+(const ExceptionAbstract::Param &p, Exc &e) {
120  e.p.initCopy(p);
121  return e;
122  }
123 
124 #endif // DYNAMICGRAPH_EXCEPTION_PASSING_PARAM
125 
126 private:
129 };
130 } // end of namespace dynamicgraph
131 
132 #endif
std::string message
Error message (can be empty).
Abstract root class for all dynamic-graph exceptions.
Class owned by exceptions to store error locations.
ExceptionEnum
Categories error code.