5#ifndef STREAMBASE_EXCEPTIONS_H
6#define STREAMBASE_EXCEPTIONS_H
8#include "StreamBase.hpp"
12#include <streambase/impl/Memory.hpp>
16#include <NMSTL/internal.hpp>
18SB_INTERNAL_FWD(XMLExceptionBuilder);
19SB_INTERNAL_FWD(Errors);
20SB_INTERNAL_FWD(StackTrace);
24#include "ExceptionCodes.hpp"
26#define SB_Throw(x) do { \
27 x.file(__FILE__).line(__LINE__).function(__FUNCTION__).throwMyself(); \
28 NMSTL_ASSERT_UNREACHABLE(); \
52 sb_internal::Errors::Type error_type = sb_internal::Errors::UNKNOWNTYPE,
53 std::string type =
"StreamBaseException");
63 sb_internal::Errors::Type error_type = sb_internal::Errors::UNKNOWNTYPE,
64 std::string type =
"StreamBaseException");
69 static StreamBaseException fromXmlString(
const std::string &xmlstring, std::shared_ptr<StreamBaseException> cause = std::shared_ptr<StreamBaseException>());
78 virtual const
char *what() const throw() {
return _message.c_str(); }
82 std::string getMessage()
const {
return _message; }
83 std::string getSummary()
const {
return _summary.empty() ? _message : _summary; }
87 std::string getFile()
const {
return _file; }
88 unsigned int getLine()
const {
return _line; }
89 std::string getFunction()
const {
return _function; }
93 std::string getType()
const {
return _type; }
97 sb_internal::Errors::Type getErrorType()
const {
return _error_type; }
100 std::string as_string()
const;
104 std::string getStackTrace()
const;
107 StreamBaseException *findByType(
const std::string type);
109 StreamBaseException& getDeepest();
112 virtual std::string asXmlStringSingle()
const;
113 virtual std::string asXmlString()
const;
114 virtual std::string chainAsString()
const;
115 virtual std::string linkAsString()
const;
116 virtual std::string getChainOfMessages()
const;
118 std::string getCode()
const {
return _code; }
119 StreamBaseException& getCause()
const {
return *_cause; }
120 bool hasCause()
const {
return _cause.get() != NULL; }
122 const std::string getParam(
const std::string name)
const;
124 const std::string getBoxParam()
const;
125 const std::string getBoxName()
const;
126 const std::string getFieldName()
const;
128 StreamBaseException& param(
const std::string name,
const std::string val);
129 StreamBaseException& param(
const std::string name,
int val);
130 StreamBaseException& code(std::string val);
131 StreamBaseException& code(
int val);
132 StreamBaseException& file(
const char *val);
133 StreamBaseException& file(std::string val);
134 StreamBaseException& line(
int val);
135 StreamBaseException& function(
const char *val);
136 StreamBaseException& function(std::string val);
137 StreamBaseException& type(std::string val);
138 StreamBaseException& message(std::string val);
139 StreamBaseException& cause(
const StreamBaseException& val);
141 StreamBaseException& summary(std::string val);
144 StreamBaseException& boxparam(std::string name);
145 StreamBaseException& boxname(std::string name);
146 StreamBaseException& fieldname(std::string name);
148 virtual void throwMyself();
152 virtual std::string causeAsXmlString()
const;
154 struct StackTraceHolder {
155 std::shared_ptr<sb_internal::StackTrace> _trace;
156 StackTraceHolder(
const std::shared_ptr<sb_internal::StackTrace>&);
157 StackTraceHolder(
const StackTraceHolder&);
158 StackTraceHolder& operator = (
const StackTraceHolder&);
162 std::string _message;
165 std::string _function;
167 StackTraceHolder _trace;
168 sb_internal::Errors::Type _error_type;
169 std::map<std::string,std::string> _params;
171 std::string _summary;
172 std::shared_ptr <StreamBaseException> _cause;
173 std::string _xmlNodeLocation;
174 friend class sb_internal::XMLExceptionBuilder;
178#define STREAMBASE_EXCEPTION_SUBTYPE(cl, parent, error_type) class cl : public parent {};
181#define STREAMBASE_EXCEPTION_SUBTYPE(cl, parent, error_type) \
182class cl : public parent { \
184 cl(std::string code, std::string message, sb_internal::Errors::Type a_error_type=error_type, const char *type=#cl) : \
185 parent(code, message, a_error_type, type ? type : #cl) {} \
186 cl(std::string code, std::string message, StreamBaseException& c, sb_internal::Errors::Type a_error_type=error_type, const char *type=#cl) : \
187 parent(code, message, c, a_error_type, type ? type : #cl) {} \
188 void throwMyself() { throw(*this); }; \
193#define STREAMBASE_EXCEPTION_TYPE(cl, error_type) \
194 STREAMBASE_EXCEPTION_SUBTYPE(cl, StreamBaseException, error_type)
238 sb_internal::Errors::Type error_type = sb_internal::Errors::UNKNOWNTYPE,
239 std::string type =
"StreamBaseXmlRpcFault");
242 sb_internal::Errors::Type error_type = sb_internal::Errors::UNKNOWNTYPE,
243 std::string type =
"StreamBaseXmlRpcFault");
247 void throwMyself() {
throw(*
this); }
254 std::vector<StreamBaseException> causes;
256 virtual std::string causeAsXmlString()
const;
259 sb_internal::Errors::Type error_type = sb_internal::Errors::UNKNOWNTYPE,
260 std::string type =
"StreamBaseListException");
264 const std::vector<StreamBaseException> &getCauses()
const {
return causes; }
265 std::string getChainOfMessages()
const;
266 std::string chainAsString()
const;
269 void throwMyself() {
throw(*
this); }
Illegal Argument.
Definition: Exceptions.hpp:228
Null value encountered.
Definition: Exceptions.hpp:231
Semantically invalid XML (e.g., box doesn't have a type).
Definition: Exceptions.hpp:204
Non-well-formed XML.
Definition: Exceptions.hpp:201
A dequeued result was not available in the time allowed.
Definition: Exceptions.hpp:225
The base class for all StreamBaseExceptions.
Definition: Exceptions.hpp:43
StreamBaseException(std::string code, std::string message, sb_internal::Errors::Type error_type=sb_internal::Errors::UNKNOWNTYPE, std::string type="StreamBaseException")
Constructor.
StreamBaseException(std::string code, std::string message, StreamBaseException &c, sb_internal::Errors::Type error_type=sb_internal::Errors::UNKNOWNTYPE, std::string type="StreamBaseException")
Constructor.
virtual ~StreamBaseException()
Destructor.
Miscellaneous illegal argument.
Definition: Exceptions.hpp:210
An Exception which contains a list of cause exceptions.
Definition: Exceptions.hpp:252
A network (TCP/IP) error was encountered.
Definition: Exceptions.hpp:219
Requested an entity which doesn't exist.
Definition: Exceptions.hpp:198
A feature is not implemented.
Definition: Exceptions.hpp:213
A feature is not supported.
Definition: Exceptions.hpp:216
A network timeout error was encountered.
Definition: Exceptions.hpp:222
Typechecking failed.
Definition: Exceptions.hpp:207
An XML/RPC error has occurred.
Definition: Exceptions.hpp:234