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:
133  ExceptionAbstract();
134 };
135 } // end of namespace dynamicgraph
136 
137 #endif
dynamicgraph::operator<<
DYNAMIC_GRAPH_DLLAPI std::ostream & operator<<(std::ostream &os, const dynamicgraph::Entity &ent)
Definition: src/dgraph/entity.cpp:174
dynamicgraph::ExceptionAbstract::Param::functionPTR
const char * functionPTR
Definition: exception-abstract.h:51
dynamicgraph::ExceptionAbstract::Param
Class owned by exceptions to store error locations.
Definition: exception-abstract.h:36
dynamic-graph-api.h
dynamicgraph
dynamicgraph::ExceptionAbstract::Param::filePTR
const char * filePTR
Definition: exception-abstract.h:54
dynamicgraph::ExceptionAbstract::~ExceptionAbstract
virtual ~ExceptionAbstract()
Definition: exception-abstract.h:78
dynamicgraph::ExceptionAbstract::ExceptionEnum
ExceptionEnum
Categories error code.
Definition: exception-abstract.h:67
dynamicgraph::ExceptionAbstract::code
int code
Error code.
Definition: exception-abstract.h:105
fwd.hh
dynamicgraph::ExceptionAbstract::Param::set
bool set
Definition: exception-abstract.h:57
dynamicgraph::ExceptionAbstract::Param::line
int line
Definition: exception-abstract.h:53
dynamicgraph::ExceptionAbstract
Abstract root class for all dynamic-graph exceptions.
Definition: exception-abstract.h:31
dynamicgraph::ExceptionAbstract::Param::pointersSet
bool pointersSet
Definition: exception-abstract.h:56
dynamicgraph::ExceptionAbstract::EXCEPTION_NAME
static const std::string EXCEPTION_NAME
Definition: exception-abstract.h:75
dynamicgraph::ExceptionAbstract::message
std::string message
Error message (can be empty).
Definition: exception-abstract.h:108
dynamicgraph::ExceptionAbstract::Param::initCopy
Param & initCopy(const Param &p)
Definition: exception-abstract.cpp:26
dynamicgraph::ExceptionAbstract::Param::Param
Param()
Definition: exception-abstract.h:41
dynamicgraph::ExceptionAbstract::what
virtual const char * what() const
Definition: exception-abstract.h:94
dynamicgraph::ExceptionAbstract::getExceptionName
virtual const std::string & getExceptionName() const
Definition: exception-abstract.h:80


dynamic-graph
Author(s): Nicolas Mansard, Olivier Stasse
autogenerated on Sun Oct 22 2023 02:27:08