BRE12
exceptions.h
1 #ifndef EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
2 #define EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
3 
4 #if defined(_MSC_VER) || \
5  (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
6  (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
7 #pragma once
8 #endif
9 
10 #include "yaml-cpp/mark.h"
11 #include "yaml-cpp/traits.h"
12 #include <sstream>
13 #include <stdexcept>
14 #include <string>
15 
16 namespace YAML {
17 // error messages
18 namespace ErrorMsg {
19 const char* const YAML_DIRECTIVE_ARGS =
20  "YAML directives must have exactly one argument";
21 const char* const YAML_VERSION = "bad YAML version: ";
22 const char* const YAML_MAJOR_VERSION = "YAML major version too large";
23 const char* const REPEATED_YAML_DIRECTIVE = "repeated YAML directive";
24 const char* const TAG_DIRECTIVE_ARGS =
25  "TAG directives must have exactly two arguments";
26 const char* const REPEATED_TAG_DIRECTIVE = "repeated TAG directive";
27 const char* const CHAR_IN_TAG_HANDLE =
28  "illegal character found while scanning tag handle";
29 const char* const TAG_WITH_NO_SUFFIX = "tag handle with no suffix";
30 const char* const END_OF_VERBATIM_TAG = "end of verbatim tag not found";
31 const char* const END_OF_MAP = "end of map not found";
32 const char* const END_OF_MAP_FLOW = "end of map flow not found";
33 const char* const END_OF_SEQ = "end of sequence not found";
34 const char* const END_OF_SEQ_FLOW = "end of sequence flow not found";
35 const char* const MULTIPLE_TAGS =
36  "cannot assign multiple tags to the same node";
37 const char* const MULTIPLE_ANCHORS =
38  "cannot assign multiple anchors to the same node";
39 const char* const MULTIPLE_ALIASES =
40  "cannot assign multiple aliases to the same node";
41 const char* const ALIAS_CONTENT =
42  "aliases can't have any content, *including* tags";
43 const char* const INVALID_HEX = "bad character found while scanning hex number";
44 const char* const INVALID_UNICODE = "invalid unicode: ";
45 const char* const INVALID_ESCAPE = "unknown escape character: ";
46 const char* const UNKNOWN_TOKEN = "unknown token";
47 const char* const DOC_IN_SCALAR = "illegal document indicator in scalar";
48 const char* const EOF_IN_SCALAR = "illegal EOF in scalar";
49 const char* const CHAR_IN_SCALAR = "illegal character in scalar";
50 const char* const TAB_IN_INDENTATION =
51  "illegal tab when looking for indentation";
52 const char* const FLOW_END = "illegal flow end";
53 const char* const BLOCK_ENTRY = "illegal block entry";
54 const char* const MAP_KEY = "illegal map key";
55 const char* const MAP_VALUE = "illegal map value";
56 const char* const ALIAS_NOT_FOUND = "alias not found after *";
57 const char* const ANCHOR_NOT_FOUND = "anchor not found after &";
58 const char* const CHAR_IN_ALIAS =
59  "illegal character found while scanning alias";
60 const char* const CHAR_IN_ANCHOR =
61  "illegal character found while scanning anchor";
62 const char* const ZERO_INDENT_IN_BLOCK =
63  "cannot set zero indentation for a block scalar";
64 const char* const CHAR_IN_BLOCK = "unexpected character in block scalar";
65 const char* const AMBIGUOUS_ANCHOR =
66  "cannot assign the same alias to multiple nodes";
67 const char* const UNKNOWN_ANCHOR = "the referenced anchor is not defined";
68 
69 const char* const INVALID_NODE =
70  "invalid node; this may result from using a map iterator as a sequence "
71  "iterator, or vice-versa";
72 const char* const INVALID_SCALAR = "invalid scalar";
73 const char* const KEY_NOT_FOUND = "key not found";
74 const char* const BAD_CONVERSION = "bad conversion";
75 const char* const BAD_DEREFERENCE = "bad dereference";
76 const char* const BAD_SUBSCRIPT = "operator[] call on a scalar";
77 const char* const BAD_PUSHBACK = "appending to a non-sequence";
78 const char* const BAD_INSERT = "inserting in a non-convertible-to-map";
79 
80 const char* const UNMATCHED_GROUP_TAG = "unmatched group tag";
81 const char* const UNEXPECTED_END_SEQ = "unexpected end sequence token";
82 const char* const UNEXPECTED_END_MAP = "unexpected end map token";
83 const char* const SINGLE_QUOTED_CHAR =
84  "invalid character in single-quoted string";
85 const char* const INVALID_ANCHOR = "invalid anchor";
86 const char* const INVALID_ALIAS = "invalid alias";
87 const char* const INVALID_TAG = "invalid tag";
88 const char* const BAD_FILE = "bad file";
89 
90 template <typename T>
91 inline const std::string KEY_NOT_FOUND_WITH_KEY(
92  const T&, typename disable_if<is_numeric<T>>::type* = 0) {
93  return KEY_NOT_FOUND;
94 }
95 
96 inline const std::string KEY_NOT_FOUND_WITH_KEY(const std::string& key) {
97  std::stringstream stream;
98  stream << KEY_NOT_FOUND << ": " << key;
99  return stream.str();
100 }
101 
102 template <typename T>
103 inline const std::string KEY_NOT_FOUND_WITH_KEY(
104  const T& key, typename enable_if<is_numeric<T>>::type* = 0) {
105  std::stringstream stream;
106  stream << KEY_NOT_FOUND << ": " << key;
107  return stream.str();
108 }
109 }
110 
111 class YAML_CPP_API Exception : public std::runtime_error {
112  public:
113  Exception(const Mark& mark_, const std::string& msg_)
114  : std::runtime_error(build_what(mark_, msg_)), mark(mark_), msg(msg_) {}
115  virtual ~Exception() noexcept;
116 
117  Exception(const Exception&) = default;
118 
119  Mark mark;
120  std::string msg;
121 
122  private:
123  static const std::string build_what(const Mark& mark,
124  const std::string& msg) {
125  if (mark.is_null()) {
126  return msg.c_str();
127  }
128 
129  std::stringstream output;
130  output << "yaml-cpp: error at line " << mark.line + 1 << ", column "
131  << mark.column + 1 << ": " << msg;
132  return output.str();
133  }
134 };
135 
136 class YAML_CPP_API ParserException : public Exception {
137  public:
138  ParserException(const Mark& mark_, const std::string& msg_)
139  : Exception(mark_, msg_) {}
140  ParserException(const ParserException&) = default;
141  virtual ~ParserException() noexcept;
142 };
143 
144 class YAML_CPP_API RepresentationException : public Exception {
145  public:
146  RepresentationException(const Mark& mark_, const std::string& msg_)
147  : Exception(mark_, msg_) {}
149  virtual ~RepresentationException() noexcept;
150 };
151 
152 // representation exceptions
153 class YAML_CPP_API InvalidScalar : public RepresentationException {
154  public:
155  InvalidScalar(const Mark& mark_)
156  : RepresentationException(mark_, ErrorMsg::INVALID_SCALAR) {}
157  InvalidScalar(const InvalidScalar&) = default;
158  virtual ~InvalidScalar() noexcept;
159 };
160 
161 class YAML_CPP_API KeyNotFound : public RepresentationException {
162  public:
163  template <typename T>
164  KeyNotFound(const Mark& mark_, const T& key_)
165  : RepresentationException(mark_, ErrorMsg::KEY_NOT_FOUND_WITH_KEY(key_)) {
166  }
167  KeyNotFound(const KeyNotFound&) = default;
168  virtual ~KeyNotFound() noexcept;
169 };
170 
171 template <typename T>
172 class YAML_CPP_API TypedKeyNotFound : public KeyNotFound {
173  public:
174  TypedKeyNotFound(const Mark& mark_, const T& key_)
175  : KeyNotFound(mark_, key_), key(key_) {}
176  virtual ~TypedKeyNotFound() noexcept {}
177 
178  T key;
179 };
180 
181 template <typename T>
182 inline TypedKeyNotFound<T> MakeTypedKeyNotFound(const Mark& mark,
183  const T& key) {
184  return TypedKeyNotFound<T>(mark, key);
185 }
186 
187 class YAML_CPP_API InvalidNode : public RepresentationException {
188  public:
189  InvalidNode()
190  : RepresentationException(Mark::null_mark(), ErrorMsg::INVALID_NODE) {}
191  InvalidNode(const InvalidNode&) = default;
192  virtual ~InvalidNode() noexcept;
193 };
194 
195 class YAML_CPP_API BadConversion : public RepresentationException {
196  public:
197  explicit BadConversion(const Mark& mark_)
198  : RepresentationException(mark_, ErrorMsg::BAD_CONVERSION) {}
199  BadConversion(const BadConversion&) = default;
200  virtual ~BadConversion() noexcept;
201 };
202 
203 template <typename T>
205  public:
206  explicit TypedBadConversion(const Mark& mark_) : BadConversion(mark_) {}
207 };
208 
209 class YAML_CPP_API BadDereference : public RepresentationException {
210  public:
212  : RepresentationException(Mark::null_mark(), ErrorMsg::BAD_DEREFERENCE) {}
213  BadDereference(const BadDereference&) = default;
214  virtual ~BadDereference() noexcept;
215 };
216 
217 class YAML_CPP_API BadSubscript : public RepresentationException {
218  public:
219  BadSubscript()
220  : RepresentationException(Mark::null_mark(), ErrorMsg::BAD_SUBSCRIPT) {}
221  BadSubscript(const BadSubscript&) = default;
222  virtual ~BadSubscript() noexcept;
223 };
224 
225 class YAML_CPP_API BadPushback : public RepresentationException {
226  public:
227  BadPushback()
228  : RepresentationException(Mark::null_mark(), ErrorMsg::BAD_PUSHBACK) {}
229  BadPushback(const BadPushback&) = default;
230  virtual ~BadPushback() noexcept;
231 };
232 
233 class YAML_CPP_API BadInsert : public RepresentationException {
234  public:
235  BadInsert()
236  : RepresentationException(Mark::null_mark(), ErrorMsg::BAD_INSERT) {}
237  BadInsert(const BadInsert&) = default;
238  virtual ~BadInsert() noexcept;
239 };
240 
241 class YAML_CPP_API EmitterException : public Exception {
242  public:
243  EmitterException(const std::string& msg_)
244  : Exception(Mark::null_mark(), msg_) {}
245  EmitterException(const EmitterException&) = default;
246  virtual ~EmitterException() noexcept;
247 };
248 
249 class YAML_CPP_API BadFile : public Exception {
250  public:
251  BadFile() : Exception(Mark::null_mark(), ErrorMsg::BAD_FILE) {}
252  BadFile(const BadFile&) = default;
253  virtual ~BadFile() noexcept;
254 };
255 }
256 
257 #endif // EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
Definition: exceptions.h:233
Definition: mark.h:13
Definition: exceptions.h:153
Definition: exceptions.h:241
Definition: exceptions.h:217
Definition: exceptions.h:249
Definition: exceptions.h:225
Definition: exceptions.h:195
Definition: exceptions.h:136
Definition: exceptions.h:204
Definition: exceptions.h:161
Definition: exceptions.h:111
Definition: exceptions.h:187
Definition: DrawableObjectLoader.h:10
Definition: exceptions.h:172
Definition: exceptions.h:209
Definition: exceptions.h:144