MIRA
Exceptions.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #ifndef _MIRA_EXCEPTIONS_H_
48 #define _MIRA_EXCEPTIONS_H_
49 
50 #include <error/Exception.h>
51 #include <factory/Factory.h>
52 
66 #define MIRA_DEFINE_SERIALIZABLE_EXCEPTION(Ex, Base) \
67  class Ex : public Base \
68  { \
69  MIRA_OBJECT(Ex) \
70  protected: \
71  friend class mira::ClassFactoryDefaultConstClassBuilder; \
72  Ex() MIRA_NOEXCEPT_OR_NOTHROW {} \
73  \
74  public: \
75  Ex(const std::string& msg, const char* file=NULL, int line=0) MIRA_NOEXCEPT_OR_NOTHROW : \
76  Base(msg, file, line) {} \
77  \
78  virtual void raise(bool recursive = false) { throw *this; } \
79  };
80 
81 namespace mira {
82 
84 
85 class SerializableException : public Object, public Exception
86 {
88 
89 protected:
92 
93 public:
94  SerializableException(const std::string& msg, const char* file=NULL, int line=0) MIRA_NOEXCEPT_OR_NOTHROW :
95  Exception(msg, file, line) {}
96 
98 
100 
101  // We do serialization of base class elements here and only use most basic serialization features,
102  // as things that we would like to use like serialization/ReflectorInterface.h and
103  // serialization/adapters/std/list depend (indirectly) on the exceptions we will define below.
104  template<typename Reflector>
105  void reflectRead(Reflector& r) {
106  uint32 count = mInfos.size();
107  r.member("InfoCount", count, "Number of info fields");
108  uint64 n = 0;
109  for (std::list<Exception::Info>::const_iterator it = mInfos.begin(); it != mInfos.end(); ++it) {
110  r.member(("Info"+std::to_string(n)+"Message").c_str(), it->message, "Message");
111  r.member(("Info"+std::to_string(n)+"File").c_str(), it->file, "File");
112  r.member(("Info"+std::to_string(n)+"Line").c_str(), it->line, "Line");
113  ++n;
114  }
115  r.member("Stack", mStack, "Call stack");
116  r.member("ThreadID", mThreadID, "Thread ID");
117  }
118 
119  template<typename Reflector>
120  void reflectWrite(Reflector& r) {
121  uint32 count;
122  r.member("InfoCount", count, "Number of info fields");
123  std::string message;
124  std::string file;
125  int line;
126  for (uint64 n = 0; n < count; ++n) {
127  r.member(("Info"+std::to_string(n)+"Message").c_str(), message, "Message");
128  r.member(("Info"+std::to_string(n)+"File").c_str(), file, "File");
129  r.member(("Info"+std::to_string(n)+"Line").c_str(), line, "Line");
130  mInfos.emplace_back(message, file, line);
131  }
132 
133  r.member("Stack", mStack, "Call stack");
134  r.member("ThreadID", mThreadID, "Thread ID");
135  }
136 
137  // C++ does not support polymorphic throw, i.e. throwing a base class reference that holds a subclass object
138  // will invoke the base class catch clause. Therefore we need to do the throw in a virtual method.
139  virtual void raise(bool recursive = false) = 0;
140 };
141 
142 typedef boost::shared_ptr<SerializableException> SerializableExceptionPtr;
143 
152 
153 
157 MIRA_DEFINE_SERIALIZABLE_EXCEPTION(XInvalidConfig, XRuntime)
158 
159 
164 
165 
169 MIRA_DEFINE_SERIALIZABLE_EXCEPTION(XConnection, XRuntime)
170 
171 
175 MIRA_DEFINE_SERIALIZABLE_EXCEPTION(XSystemCall, XRuntime)
176 
177 
181 MIRA_DEFINE_SERIALIZABLE_EXCEPTION(XFileNotFound, XIO)
182 
183 
187 MIRA_DEFINE_SERIALIZABLE_EXCEPTION(XNotImplemented, XRuntime)
188 
189 
193 MIRA_DEFINE_SERIALIZABLE_EXCEPTION(XTimeout, XRuntime)
194 
195 
203 
204 
208 MIRA_DEFINE_SERIALIZABLE_EXCEPTION(XInvalidParameter, XLogical)
209 
210 
216 MIRA_DEFINE_SERIALIZABLE_EXCEPTION(XAssertion, XLogical)
217 
218 
226 MIRA_DEFINE_SERIALIZABLE_EXCEPTION(XBadCast, XRuntime)
227 
228 
232 MIRA_DEFINE_SERIALIZABLE_EXCEPTION(XAccessViolation, XRuntime)
233 
234 
240 
241 
243 }
244 
245 #endif
MIRA_SPLIT_REFLECT_MEMBER void reflectRead(Reflector &r)
Definition: Exceptions.h:105
CallStack mStack
Definition: Exception.h:315
PropertyHint file(const std::string &filters=std::string(), bool save=false)
Tells the property editor that the path is for a file, and that it should show a "File Open"/"File Sa...
Definition: Path.h:247
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
SerializableException()
Definition: Exceptions.h:91
#define MIRA_SPLIT_REFLECT_MEMBER
Macro that insert a class member reflect() method just splitting reflection into a reflectRead() and ...
Definition: SplitReflect.h:238
#define MIRA_DEFINE_SERIALIZABLE_EXCEPTION(Ex, Base)
Macro for easily defining a new serializable exception class.
Definition: Exceptions.h:66
ThreadID mThreadID
Definition: Exception.h:316
$Header file containing base classes to enable class creation using a class factory$ ...
std::string message() const MIRA_NOEXCEPT_OR_NOTHROW
Similar to what().
The object class acts as a generic base class for classes which should be used with the classFactory...
Definition: Object.h:144
SerializableException(const std::string &msg, const char *file=NULL, int line=0) MIRA_NOEXCEPT_OR_NOTHROW
Definition: Exceptions.h:94
#define MIRA_NOEXCEPT_OR_NOTHROW
Definition: NoExcept.h:99
std::list< Info > mInfos
Definition: Exception.h:314
#define MIRA_OBJECT(classIdentifier)
Use this MACRO if you like the factory to automatically extract the class name from the given identif...
Definition: FactoryMacros.h:183
Base class for exceptions.
Definition: Exception.h:194
friend class ClassFactoryDefaultConstClassBuilder
Definition: Exceptions.h:90
void reflectWrite(Reflector &r)
Definition: Exceptions.h:120
virtual ~SerializableException() MIRA_NOEXCEPT_OR_NOTHROW
Definition: Exceptions.h:97
boost::shared_ptr< SerializableException > SerializableExceptionPtr
Definition: Exceptions.h:142
Exception base class.
Definition: Exceptions.h:85