Gyoto
GyotoError.h
Go to the documentation of this file.
1 
34 /*
35  Copyright 2011, 2013 Thibaut Paumard
36 
37  This file is part of Gyoto.
38 
39  Gyoto is free software: you can redistribute it and/or modify
40  it under the terms of the GNU General Public License as published by
41  the Free Software Foundation, either version 3 of the License, or
42  (at your option) any later version.
43 
44  Gyoto is distributed in the hope that it will be useful,
45  but WITHOUT ANY WARRANTY; without even the implied warranty of
46  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
47  GNU General Public License for more details.
48 
49  You should have received a copy of the GNU General Public License
50  along with Gyoto. If not, see <http://www.gnu.org/licenses/>.
51  */
52 
53 #ifndef __GyotoError_H_
54 #define __GyotoError_H_
55 
61 #include <string>
62 #include <boost/stacktrace.hpp>
63 
64 #include "GyotoDefs.h"
65 
66 namespace Gyoto {
67  class Error;
68 }
69 
103 {
104  private:
106  const std::string message;
107  std::string stacktrace;
108  std::string fullmessage;
109 
111 
115  const int errcode;
116 
117  public:
118 
120  Error(const std::string &m, boost::stacktrace::stacktrace const &trace);
121 
122  // Copy constructor
123  Error( const Gyoto::Error &o);
124 
126  void Report() const ;
127 
129 
133  int getErrcode() const ;
134 
136 
140  operator const char * () const;
141 
143 
149  std::string get_message() const ;
150 
152 
158  std::string get_stacktrace() const ;
159 
161 
174  typedef void Handler_t (const Error);
175 
177 
193  static void setHandler( Gyoto::Error::Handler_t* phandler);
194 
195 };
196 
197 namespace Gyoto {
199 
202  void throwError(std::string const &, boost::stacktrace::stacktrace const &trace);
203 }
204 
205 
207 
211 #define GYOTO_ERROR(msg) \
212  Gyoto::throwError(std::string(__FILE__ ":" GYOTO_STRINGIFY(__LINE__) " in ") \
213  + __PRETTY_FUNCTION__ + ": " + msg, \
214  boost::stacktrace::stacktrace())
215 
216 #endif
static void setHandler(Gyoto::Error::Handler_t *phandler)
Set application error handler.
const std::string message
Error message.
Definition: GyotoError.h:106
Error(const std::string &m, boost::stacktrace::stacktrace const &trace)
Constructor with an error message.
Class for thowing exceptions.
Definition: GyotoError.h:102
std::string get_message() const
Retrieve error message for custom handling of the exception.
void throwError(std::string const &, boost::stacktrace::stacktrace const &trace)
Throw a Gyoto::Error.
std::string get_stacktrace() const
Retrieve stacktrace description for custom handling of the exception.
const int errcode
Error code.
Definition: GyotoError.h:115
Gyoto ubiquitous macros and typedefs.
Namespace for the Gyoto library.
Definition: GyotoAnsi.h:245
void Handler_t(const Error)
Error handler type.
Definition: GyotoError.h:174
int getErrcode() const
Retrieve error code.
void Report() const
Print-out error message on standard error.