5 #ifndef STREAMBASE_EXCEPTIONS_H
6 #define STREAMBASE_EXCEPTIONS_H
8 #include "StreamBase.hpp"
11 #include <NMSTL/ptr.hpp>
14 SB_INTERNAL_FWD(XMLExceptionBuilder);
15 SB_INTERNAL_FWD(Errors);
16 SB_INTERNAL_FWD(StackTrace);
20 #include "ExceptionCodes.hpp"
22 #define SB_Throw(x) do { \
23 x.file(__FILE__).line(__LINE__).function(__FUNCTION__).throwMyself(); \
24 NMSTL_ASSERT_UNREACHABLE(); \
48 sb_internal::Errors::Type error_type = sb_internal::Errors::UNKNOWNTYPE,
49 std::string type =
"StreamBaseException");
59 sb_internal::Errors::Type error_type = sb_internal::Errors::UNKNOWNTYPE,
60 std::string type =
"StreamBaseException");
65 static StreamBaseException fromXmlString(
const std::string &xmlstring, NMSTL::ptr<StreamBaseException> cause = NMSTL::ptr<StreamBaseException>());
74 virtual const char *
what()
const throw() {
return _message.c_str(); }
78 std::string getMessage()
const {
return _message; }
79 std::string getSummary()
const {
return _summary.empty() ? _message : _summary; }
83 std::string getFile()
const {
return _file; }
84 unsigned int getLine()
const {
return _line; }
85 std::string getFunction()
const {
return _function; }
89 std::string getType()
const {
return _type; }
93 sb_internal::Errors::Type getErrorType()
const {
return _error_type; }
96 std::string as_string()
const;
100 std::string getStackTrace()
const;
103 StreamBaseException *findByType(
const std::string type);
105 StreamBaseException& getDeepest();
108 virtual std::string asXmlStringSingle()
const;
109 virtual std::string asXmlString()
const;
110 virtual std::string chainAsString()
const;
111 virtual std::string linkAsString()
const;
112 virtual std::string getChainOfMessages()
const;
114 std::string getCode()
const {
return _code; }
115 StreamBaseException& getCause()
const {
return *_cause; }
116 bool hasCause()
const {
return _cause; }
118 const std::string getParam(
const std::string name)
const;
120 const std::string getBoxParam()
const;
121 const std::string getBoxName()
const;
122 const std::string getFieldName()
const;
124 StreamBaseException& param(
const std::string name,
const std::string val);
125 StreamBaseException& param(
const std::string name,
int val);
126 StreamBaseException& code(std::string val);
127 StreamBaseException& code(
int val);
128 StreamBaseException& file(
const char *val);
129 StreamBaseException& file(std::string val);
130 StreamBaseException& line(
int val);
131 StreamBaseException&
function(
const char *val);
132 StreamBaseException&
function(std::string val);
133 StreamBaseException& type(std::string val);
134 StreamBaseException& message(std::string val);
135 StreamBaseException& cause(
const StreamBaseException& val);
137 StreamBaseException& summary(std::string val);
140 StreamBaseException& boxparam(std::string name);
141 StreamBaseException& boxname(std::string name);
142 StreamBaseException& fieldname(std::string name);
144 virtual void throwMyself();
148 virtual std::string causeAsXmlString()
const;
150 struct StackTraceHolder {
151 NMSTL::ptr<sb_internal::StackTrace> _trace;
152 StackTraceHolder(
const NMSTL::ptr<sb_internal::StackTrace>&);
153 StackTraceHolder(
const StackTraceHolder&);
154 StackTraceHolder& operator = (
const StackTraceHolder&);
158 std::string _message;
161 std::string _function;
163 StackTraceHolder _trace;
164 sb_internal::Errors::Type _error_type;
165 std::map<std::string,std::string> _params;
167 std::string _summary;
168 NMSTL::ptr<StreamBaseException> _cause;
169 std::string _xmlNodeLocation;
170 friend class sb_internal::XMLExceptionBuilder;
174 #define STREAMBASE_EXCEPTION_SUBTYPE(cl, parent, error_type) class cl : public parent {};
177 #define STREAMBASE_EXCEPTION_SUBTYPE(cl, parent, error_type) \
178 class cl : public parent { \
180 cl(std::string code, std::string message, sb_internal::Errors::Type a_error_type=error_type, const char *type=#cl) : \
181 parent(code, message, a_error_type, type ? type : #cl) {} \
182 cl(std::string code, std::string message, StreamBaseException& c, sb_internal::Errors::Type a_error_type=error_type, const char *type=#cl) : \
183 parent(code, message, c, a_error_type, type ? type : #cl) {} \
184 void throwMyself() { throw(*this); }; \
187 #endif // DOXYGEN_SKIP
189 #define STREAMBASE_EXCEPTION_TYPE(cl, error_type) \
190 STREAMBASE_EXCEPTION_SUBTYPE(cl, StreamBaseException, error_type)
234 sb_internal::Errors::Type error_type = sb_internal::Errors::UNKNOWNTYPE,
235 std::string type =
"StreamBaseXmlRpcFault");
238 sb_internal::Errors::Type error_type = sb_internal::Errors::UNKNOWNTYPE,
239 std::string type =
"StreamBaseXmlRpcFault");
243 void throwMyself() {
throw(*
this); }
250 std::vector<StreamBaseException> causes;
252 virtual std::string causeAsXmlString()
const;
255 sb_internal::Errors::Type error_type = sb_internal::Errors::UNKNOWNTYPE,
256 std::string type =
"StreamBaseListException");
260 const std::vector<StreamBaseException> &getCauses()
const {
return causes; }
261 std::string getChainOfMessages()
const;
262 std::string chainAsString()
const;
265 void throwMyself() {
throw(*
this); }