6#include <bond/core/config.h>
8#include "detail/string_stream.h"
10#include <bond/core/bond_types.h>
12#include <boost/locale/encoding_utf.hpp>
13#include <boost/utility/enable_if.hpp>
15#define BOND_THROW(x, y) throw x((::bond::detail::basic_string_stream<1024>() << y).content());
22 :
public std::exception,
23 public SerializableExceptionBase
26 const char* what()
const BOND_NOEXCEPT
28 return message.c_str();
31 virtual ~Exception() BOND_NOEXCEPT
35 Exception(
const char* msg) BOND_NOEXCEPT
40 Exception() BOND_NOEXCEPT
50 CoreException(
const char* message)
56[[noreturn]]
inline void MergerContainerException(uint32_t payload, uint32_t obj)
59 "Merge failed: container mismatch, length in the payload: "
60 << payload <<
" length in the object: " << obj);
64[[noreturn]]
inline void InvalidKeyTypeException()
66 BOND_THROW(CoreException,
67 "Map key type not valid");
70[[noreturn]]
inline void UnknownDataTypeException()
73 "Unknown data type found");
76[[noreturn]]
inline void ExceededMaxRecursionDepthException()
79 "Max recursion depth exceeded");
82[[noreturn]]
inline void OutOfBoundObjectSizeException()
85 "Payload had an element size larger than the input buffer");
88[[noreturn]]
inline void OutOfBoundStringSizeException()
91 "Payload-specified string length exceeds the input buffer size");
96 template <
typename Key>
97 [[noreturn]]
inline void ElementNotFoundExceptionHelper(
99 typename boost::enable_if<is_wstring<Key>>::type* =
nullptr)
103 BOND_THROW(CoreException,
104 "Map element not found: key: " <<
105 boost::locale::conv::utf_to_utf<char>(
107 string_data(key) + string_length(key),
108 boost::locale::conv::stop));
110 catch (boost::locale::conv::conversion_error &)
112 BOND_THROW(CoreException,
"Map element not found: key: <bad wstring>");
116 template <
typename Key>
117 [[noreturn]]
inline void ElementNotFoundExceptionHelper(
119 typename boost::disable_if<is_wstring<Key>>::type* =
nullptr)
121 BOND_THROW(CoreException,
122 "Map element not found: key: " << key);
127template <
typename Key>
128[[noreturn]]
inline void ElementNotFoundException(
const Key& key)
130 detail::ElementNotFoundExceptionHelper(key);
134[[noreturn]]
inline void UnknownProtocolException()
137 "Unmarshaling failed: unsupported protocol");
141[[noreturn]]
inline void UnknownProtocolException(uint16_t magic)
144 "Unsupported protocol: "
145 << (
char)(magic & 0xFF) << (
char)(magic >> 8));
149[[noreturn]]
inline void NothingException()
152 "Field value is 'nothing'");
156[[noreturn]]
inline void InvalidEnumValueException(
const char* value,
const char* enum_)
158 BOND_THROW(bond::CoreException,
159 "Unexpected value " << value <<
" for enum " << enum_);
163[[noreturn]]
inline void InvalidEnumValueException(int32_t value,
const char* enum_)
165 BOND_THROW(bond::CoreException,
166 "Unexpected value " << value <<
" for enum " << enum_);
170[[noreturn]]
inline void RapidJsonException(
const char* error,
size_t offset)
173 "JSON parser error: " << error <<
" at offset " << offset);
177[[noreturn]]
inline void UnicodeConversionException()
180 "Unicode conversion exception");
184struct StreamException
187 StreamException(
const char* message)
193struct SchemaValidateException
196 SchemaValidateException(
const char* message)
197 : CoreException(message)
203inline void StructBaseDifferentException(
const StructDef& src,
204 const StructDef& dst)
206 BOND_THROW(SchemaValidateException,
207 "Schemas are incompatible; struct base different: "
208 << src.metadata.name <<
", " << dst.metadata.name);
213inline void RequiredFieldMissingException(
const StructDef& s_dst,
214 const FieldDef& f_dst)
216 BOND_THROW(SchemaValidateException,
217 "Schemas are incompatible; required field missing: "
218 << s_dst.metadata.name <<
"::" << f_dst.metadata.name);
223inline void OptionalToRequiredException(
const StructDef& s_src,
224 const StructDef& s_dst,
225 const FieldDef& f_src,
226 const FieldDef& f_dst)
228 BOND_THROW(SchemaValidateException,
229 "Schemas are incompatible; required modifier removed: "
230 << s_src.metadata.name <<
"::" << f_src.metadata.name <<
", "
231 << s_dst.metadata.name <<
"::" << f_dst.metadata.name);
236inline void FieldTypeIncompatibleException(
const StructDef& s_src,
237 const StructDef& s_dst,
238 const FieldDef& f_src,
239 const FieldDef& f_dst)
241 BOND_THROW(SchemaValidateException,
242 "Schemas are incompatible; field types incompatible: "
243 << s_src.metadata.name <<
"::" << f_src.metadata.name <<
", "
244 << s_dst.metadata.name <<
"::" << f_dst.metadata.name);
248[[noreturn]]
inline void UnknownSchemaDefException(uint16_t
id)
250 BOND_THROW(SchemaValidateException,
251 "Failed to validate schema compatibility; "
252 "SchemaDef contains unknown field: " <<
id);
Base type for all Bond exceptions.
Definition exception.h:24
namespace bond
Definition apply.h:17
Exception used to indicate an error during serialization or deserialization.
Definition exception.h:49