data_exception.hpp
Go to the documentation of this file.
1 
11 /*****************************************************************************
12 ** Ifdefs
13 *****************************************************************************/
14 
15 #ifndef ECL_EXCEPTIONS_DATA_EXCEPTION_HPP_
16 #define ECL_EXCEPTIONS_DATA_EXCEPTION_HPP_
17 
18 /*****************************************************************************
19 ** Disable check
20 *****************************************************************************/
21 
22 #include <ecl/config/ecl.hpp>
23 #ifndef ECL_DISABLE_EXCEPTIONS
24 
25 /*****************************************************************************
26 ** Includes
27 *****************************************************************************/
28 
29 #include <string>
30 #include <sstream>
31 #include <ecl/errors/handlers.hpp>
32 #include "exception.hpp"
33 #include <ecl/errors/macros.hpp>
34 
35 /*****************************************************************************
36 ** Namespaces
37 *****************************************************************************/
38 
39 namespace ecl {
40 
41 /*****************************************************************************
42 ** Interface [DataException<Data>]
43 *****************************************************************************/
57 template <typename Data>
58 class DataException : public Exception
59 {
60  public:
61  DataException(const char* loc, ErrorFlag error, Data &d );
62  DataException(const char* loc, ErrorFlag error, const std::string &msg, const Data &d );
63  DataException(const char* loc, const DataException<Data> &e );
64 
65  virtual ~DataException() throw() {}
66 
67  const char* what() const throw();
68 
69  const ErrorFlag& flag() const { return error_type; }
70  const Data& data() const { return error_data; }
72  private:
74  Data error_data;
75  std::string message;
76 };
77 
78 /*****************************************************************************
79  * Implementation
80  ****************************************************************************/
87 template <typename Data>
88 DataException<Data>::DataException(const char* loc, ErrorFlag error, Data &d ) :
89  Exception(loc),
90  error_type(error),
91  error_data(d)
92 {}
100 template <typename Data>
101 DataException<Data>::DataException(const char* loc, ErrorFlag error, const std::string &msg, const Data &d ) :
102  Exception(loc),
103  error_type(error),
104  error_data(d),
105  message(msg)
106 {}
113 template <typename Data>
115  Exception(loc),
116  error_type(e.flag()),
117  error_data(e.data()),
118  message(e.message)
119 {
120  location = std::string(loc) + "\n : " + e.location;
121 }
127 template <typename Data>
128 const char* DataException<Data>::what() const throw() {
129 
130  std::string what_msg;
131 
132  std::ostringstream stream;
133  stream << "\n" << "Location : " << this->location << "\n";
134  stream << "Flag : " << Error(error_type).what() << "\n";
135  if ( message.size() > 0 ) {
136  stream << "Detail : " << message << "\n";
137  }
138  stream << "Data : " << error_data << "\n";
139  what_msg = stream.str();
140  return what_msg.c_str();
141 }
142 
143 }; // namespace ecl
144 
145 #endif /* ECL_DISABLE_EXCEPTIONS */
146 #endif /* ECL_EXCEPTIONS_DATA_EXCEPTION_HPP_*/
virtual const char * what() const
Extended exception class that bundles location, message and data.
Virtual parent class for the ecl exceptions.
Definition: exception.hpp:49
const Data & data() const
The bundled data object.
Macros and exceptions for try-catch handling within the ecl.
DataException(const char *loc, ErrorFlag error, Data &d)
const ErrorFlag & flag() const
Flag enumerating the type of exception thrown.
const char * what() const
std::string location
Definition: exception.hpp:68


ecl_exceptions
Author(s): Daniel Stonier
autogenerated on Mon Jun 10 2019 13:08:12