exception-abstract.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2010,
3  * François Bleibel,
4  * Olivier Stasse,
5  *
6  * CNRS/AIST
7  *
8  */
9 
10 #ifndef __SOT_ABSTRACT_EXCEPTION_H
11 #define __SOT_ABSTRACT_EXCEPTION_H
12 
13 /* --------------------------------------------------------------------- */
14 /* --- INCLUDE --------------------------------------------------------- */
15 /* --------------------------------------------------------------------- */
16 
17 /* Classes standards. */
18 #include <exception>
19 #include <ostream> /* Classe ostream. */
20 #include <string> /* Classe string. */
21 
22 #include "sot/core/api.hh"
23 
24 // Uncomment this macros to have lines parameter on the throw display
25 // #define SOT_EXCEPTION_PASSING_PARAM
26 
27 /* --------------------------------------------------------------------- */
28 /* --- CLASS ----------------------------------------------------------- */
29 /* --------------------------------------------------------------------- */
30 
31 namespace dynamicgraph {
32 namespace sot {
33 
34 /* \class ExceptionAbstract
35  */
36 class SOT_CORE_EXPORT ExceptionAbstract : public std::exception {
37  public:
39  ABSTRACT = 0,
40  SIGNAL = 100,
41  TASK = 200,
42  FEATURE = 300,
43  FACTORY = 400,
44  DYNAMIC = 500,
45  TRACES = 600,
46  TOOLS = 700,
47  PATTERN_GENERATOR = 800
48  };
49 
50  static const std::string EXCEPTION_NAME;
51  virtual const std::string &getExceptionName(void) const {
52  return EXCEPTION_NAME;
53  }
54 
55  protected:
58  int code;
59 
61  std::string message;
62 
63  private:
65  ExceptionAbstract(void);
66 
67  public:
68  ExceptionAbstract(const int &code, const std::string &msg = "");
69  virtual ~ExceptionAbstract(void) throw() {}
70 
72  int getCode(void);
73 
75  const std::string &getStringMessage(void);
76 
80  const char *getMessage(void);
81  const char *what() const throw();
82 
84  SOT_CORE_EXPORT friend std::ostream &operator<<(std::ostream &os,
85  const ExceptionAbstract &err);
86 
87 #ifdef SOT_EXCEPTION_PASSING_PARAM
88  public:
89  class Param {
90  public:
91  static const int BUFFER_SIZE = 80;
92 
93  const char *functionPTR;
94  char function[BUFFER_SIZE];
95  int line;
96  const char *filePTR;
97  char file[BUFFER_SIZE];
98  bool pointersSet, set;
99 
100  public:
101  Param(const int &_line, const char *_function, const char *_file);
102  Param(void) : pointersSet(false), set(false) {}
103  Param &initCopy(const Param &p);
104  };
105 
106  protected:
107  mutable Param p;
108 
109  template <class Exc>
110  friend const Exc &operator+(const ExceptionAbstract::Param &p, const Exc &e) {
111  e.p.initCopy(p);
112  return e;
113  }
114  template <class Exc>
115  friend Exc &operator+(const ExceptionAbstract::Param &p, Exc &e) {
116  e.p.initCopy(p);
117  return e;
118  }
119 #endif // #ifdef SOT_EXCEPTION_PASSING_PARAM
120 };
121 
122 #define SOT_RETHROW \
123  (const ExceptionAbstract &err) { throw err; }
124 
125 #ifdef SOT_EXCEPTION_PASSING_PARAM
126 #define SOT_THROW \
127  throw ExceptionAbstract::Param(__LINE__, __FUNCTION__, __FILE__) +
128 #else // #ifdef SOT_EXCEPTION_PASSING_PARAM
129 #define SOT_THROW throw
130 #endif // #ifdef SOT_EXCEPTION_PASSING_PARAM
131 
132 } /* namespace sot */
133 } /* namespace dynamicgraph */
134 
135 #endif /* #ifndef __SOT_ABSTRACT_EXCEPTION_H */
136 
137 /*
138  * Local variables:
139  * c-basic-offset: 2
140  * End:
141  */
virtual const std::string & getExceptionName(void) const
static const std::string EXCEPTION_NAME
OBBRSS operator+(const OBBRSS &other) const
#define SOT_CORE_EXPORT
Definition: api.hh:20
SOT_CORE_EXPORT std::ostream & operator<<(std::ostream &os, const VectorMultiBound &v)
int line
p
err


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Wed Jun 21 2023 02:51:26