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();
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");
73 template <
typename Key>
74 [[noreturn]]
inline void ElementNotFoundExceptionHelper(
76 typename boost::enable_if<is_wstring<Key>>::type* =
nullptr)
80 BOND_THROW(CoreException,
81 "Map element not found: key: " <<
82 boost::locale::conv::utf_to_utf<char>(
84 string_data(key) + string_length(key),
85 boost::locale::conv::stop));
87 catch (boost::locale::conv::conversion_error &)
89 BOND_THROW(CoreException,
"Map element not found: key: <bad wstring>");
93 template <
typename Key>
94 [[noreturn]]
inline void ElementNotFoundExceptionHelper(
96 typename boost::disable_if<is_wstring<Key>>::type* =
nullptr)
98 BOND_THROW(CoreException,
99 "Map element not found: key: " << key);
104template <
typename Key>
105[[noreturn]]
inline void ElementNotFoundException(
const Key& key)
107 detail::ElementNotFoundExceptionHelper(key);
111[[noreturn]]
inline void UnknownProtocolException()
113 BOND_THROW(CoreException,
114 "Unmarshaling failed: unsupported protocol");
118[[noreturn]]
inline void UnknownProtocolException(uint16_t magic)
120 BOND_THROW(CoreException,
121 "Unsupported protocol: "
122 << (
char)(magic & 0xFF) << (
char)(magic >> 8));
126[[noreturn]]
inline void NothingException()
128 BOND_THROW(CoreException,
129 "Field value is 'nothing'");
133[[noreturn]]
inline void InvalidEnumValueException(
const char* value,
const char* enum_)
136 "Unexpected value " << value <<
" for enum " << enum_);
140[[noreturn]]
inline void InvalidEnumValueException(int32_t value,
const char* enum_)
143 "Unexpected value " << value <<
" for enum " << enum_);
147[[noreturn]]
inline void RapidJsonException(
const char* error,
size_t offset)
149 BOND_THROW(CoreException,
150 "JSON parser error: " << error <<
" at offset " << offset);
154[[noreturn]]
inline void UnicodeConversionException()
156 BOND_THROW(CoreException,
157 "Unicode conversion exception");
161struct StreamException
164 StreamException(
const char* message)
170struct SchemaValidateException
173 SchemaValidateException(
const char* message)
174 : CoreException(message)
180inline void StructBaseDifferentException(
const StructDef& src,
181 const StructDef& dst)
183 BOND_THROW(SchemaValidateException,
184 "Schemas are incompatible; struct base different: "
185 << src.metadata.name <<
", " << dst.metadata.name);
190inline void RequiredFieldMissingException(
const StructDef& s_dst,
191 const FieldDef& f_dst)
193 BOND_THROW(SchemaValidateException,
194 "Schemas are incompatible; required field missing: "
195 << s_dst.metadata.name <<
"::" << f_dst.metadata.name);
200inline void OptionalToRequiredException(
const StructDef& s_src,
201 const StructDef& s_dst,
202 const FieldDef& f_src,
203 const FieldDef& f_dst)
205 BOND_THROW(SchemaValidateException,
206 "Schemas are incompatible; required modifier removed: "
207 << s_src.metadata.name <<
"::" << f_src.metadata.name <<
", "
208 << s_dst.metadata.name <<
"::" << f_dst.metadata.name);
213inline void FieldTypeIncompatibleException(
const StructDef& s_src,
214 const StructDef& s_dst,
215 const FieldDef& f_src,
216 const FieldDef& f_dst)
218 BOND_THROW(SchemaValidateException,
219 "Schemas are incompatible; field types incompatible: "
220 << s_src.metadata.name <<
"::" << f_src.metadata.name <<
", "
221 << s_dst.metadata.name <<
"::" << f_dst.metadata.name);
225[[noreturn]]
inline void UnknownSchemaDefException(uint16_t
id)
227 BOND_THROW(SchemaValidateException,
228 "Failed to validate schema compatibility; "
229 "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