1 #ifndef EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 2 #define EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 4 #if defined(_MSC_VER) || \ 5 (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ 6 (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 10 #include "yaml-cpp/mark.h" 11 #include "yaml-cpp/noexcept.h" 12 #include "yaml-cpp/traits.h" 20 const char*
const YAML_DIRECTIVE_ARGS =
21 "YAML directives must have exactly one argument";
22 const char*
const YAML_VERSION =
"bad YAML version: ";
23 const char*
const YAML_MAJOR_VERSION =
"YAML major version too large";
24 const char*
const REPEATED_YAML_DIRECTIVE =
"repeated YAML directive";
25 const char*
const TAG_DIRECTIVE_ARGS =
26 "TAG directives must have exactly two arguments";
27 const char*
const REPEATED_TAG_DIRECTIVE =
"repeated TAG directive";
28 const char*
const CHAR_IN_TAG_HANDLE =
29 "illegal character found while scanning tag handle";
30 const char*
const TAG_WITH_NO_SUFFIX =
"tag handle with no suffix";
31 const char*
const END_OF_VERBATIM_TAG =
"end of verbatim tag not found";
32 const char*
const END_OF_MAP =
"end of map not found";
33 const char*
const END_OF_MAP_FLOW =
"end of map flow not found";
34 const char*
const END_OF_SEQ =
"end of sequence not found";
35 const char*
const END_OF_SEQ_FLOW =
"end of sequence flow not found";
36 const char*
const MULTIPLE_TAGS =
37 "cannot assign multiple tags to the same node";
38 const char*
const MULTIPLE_ANCHORS =
39 "cannot assign multiple anchors to the same node";
40 const char*
const MULTIPLE_ALIASES =
41 "cannot assign multiple aliases to the same node";
42 const char*
const ALIAS_CONTENT =
43 "aliases can't have any content, *including* tags";
44 const char*
const INVALID_HEX =
"bad character found while scanning hex number";
45 const char*
const INVALID_UNICODE =
"invalid unicode: ";
46 const char*
const INVALID_ESCAPE =
"unknown escape character: ";
47 const char*
const UNKNOWN_TOKEN =
"unknown token";
48 const char*
const DOC_IN_SCALAR =
"illegal document indicator in scalar";
49 const char*
const EOF_IN_SCALAR =
"illegal EOF in scalar";
50 const char*
const CHAR_IN_SCALAR =
"illegal character in scalar";
51 const char*
const UNEXPECTED_SCALAR =
"unexpected scalar";
52 const char*
const UNEXPECTED_FLOW =
"plain value cannot start with flow indicator character";
53 const char*
const TAB_IN_INDENTATION =
54 "illegal tab when looking for indentation";
55 const char*
const FLOW_END =
"illegal flow end";
56 const char*
const BLOCK_ENTRY =
"illegal block entry";
57 const char*
const MAP_KEY =
"illegal map key";
58 const char*
const MAP_VALUE =
"illegal map value";
59 const char*
const ALIAS_NOT_FOUND =
"alias not found after *";
60 const char*
const ANCHOR_NOT_FOUND =
"anchor not found after &";
61 const char*
const CHAR_IN_ALIAS =
62 "illegal character found while scanning alias";
63 const char*
const CHAR_IN_ANCHOR =
64 "illegal character found while scanning anchor";
65 const char*
const ZERO_INDENT_IN_BLOCK =
66 "cannot set zero indentation for a block scalar";
67 const char*
const CHAR_IN_BLOCK =
"unexpected character in block scalar";
68 const char*
const AMBIGUOUS_ANCHOR =
69 "cannot assign the same alias to multiple nodes";
70 const char*
const UNKNOWN_ANCHOR =
"the referenced anchor is not defined: ";
72 const char*
const INVALID_NODE =
73 "invalid node; this may result from using a map iterator as a sequence " 74 "iterator, or vice-versa";
75 const char*
const INVALID_SCALAR =
"invalid scalar";
76 const char*
const KEY_NOT_FOUND =
"key not found";
77 const char*
const BAD_CONVERSION =
"bad conversion";
78 const char*
const BAD_DEREFERENCE =
"bad dereference";
79 const char*
const BAD_SUBSCRIPT =
"operator[] call on a scalar";
80 const char*
const BAD_PUSHBACK =
"appending to a non-sequence";
81 const char*
const BAD_INSERT =
"inserting in a non-convertible-to-map";
83 const char*
const UNMATCHED_GROUP_TAG =
"unmatched group tag";
84 const char*
const UNEXPECTED_END_SEQ =
"unexpected end sequence token";
85 const char*
const UNEXPECTED_END_MAP =
"unexpected end map token";
86 const char*
const SINGLE_QUOTED_CHAR =
87 "invalid character in single-quoted string";
88 const char*
const INVALID_ANCHOR =
"invalid anchor";
89 const char*
const INVALID_ALIAS =
"invalid alias";
90 const char*
const INVALID_TAG =
"invalid tag";
91 const char*
const BAD_FILE =
"bad file";
94 inline const std::string KEY_NOT_FOUND_WITH_KEY(
95 const T&,
typename disable_if<is_numeric<T>>::type* = 0) {
99 inline const std::string KEY_NOT_FOUND_WITH_KEY(
const std::string& key) {
100 std::stringstream stream;
101 stream << KEY_NOT_FOUND <<
": " << key;
105 inline const std::string KEY_NOT_FOUND_WITH_KEY(
const char* key) {
106 std::stringstream stream;
107 stream << KEY_NOT_FOUND <<
": " << key;
111 template <
typename T>
112 inline const std::string KEY_NOT_FOUND_WITH_KEY(
113 const T& key,
typename enable_if<is_numeric<T>>::type* = 0) {
114 std::stringstream stream;
115 stream << KEY_NOT_FOUND <<
": " << key;
119 template <
typename T>
120 inline const std::string BAD_SUBSCRIPT_WITH_KEY(
121 const T&,
typename disable_if<is_numeric<T>>::type* =
nullptr) {
122 return BAD_SUBSCRIPT;
125 inline const std::string BAD_SUBSCRIPT_WITH_KEY(
const std::string& key) {
126 std::stringstream stream;
127 stream << BAD_SUBSCRIPT <<
" (key: \"" << key <<
"\")";
131 inline const std::string BAD_SUBSCRIPT_WITH_KEY(
const char* key) {
132 std::stringstream stream;
133 stream << BAD_SUBSCRIPT <<
" (key: \"" << key <<
"\")";
137 template <
typename T>
138 inline const std::string BAD_SUBSCRIPT_WITH_KEY(
139 const T& key,
typename enable_if<is_numeric<T>>::type* =
nullptr) {
140 std::stringstream stream;
141 stream << BAD_SUBSCRIPT <<
" (key: \"" << key <<
"\")";
145 inline const std::string INVALID_NODE_WITH_KEY(
const std::string& key) {
146 std::stringstream stream;
150 stream <<
"invalid node; first invalid key: \"" << key <<
"\"";
155 class YAML_CPP_API
Exception :
public std::runtime_error {
158 : std::runtime_error(build_what(mark_, msg_)), mark(mark_), msg(msg_) {}
167 static const std::string build_what(
const Mark& mark,
168 const std::string& msg) {
169 if (mark.is_null()) {
173 std::stringstream output;
174 output <<
"yaml-cpp: error at line " << mark.line + 1 <<
", column " 175 << mark.column + 1 <<
": " << msg;
207 template <
typename T>
215 template <
typename T>
225 template <
typename T>
235 ErrorMsg::INVALID_NODE_WITH_KEY(key)) {}
248 template <
typename T>
264 template <
typename Key>
297 explicit BadFile(
const std::string& filename)
299 std::string(ErrorMsg::BAD_FILE) +
": " + filename) {}
301 ~
BadFile() YAML_CPP_NOEXCEPT
override;
305 #endif // EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 Definition: exceptions.h:279
Definition: exceptions.h:197
Definition: exceptions.h:287
Definition: exceptions.h:262
Definition: exceptions.h:295
Definition: exceptions.h:271
Definition: exceptions.h:240
Definition: exceptions.h:180
Definition: exceptions.h:249
Definition: exceptions.h:205
Definition: exceptions.h:155
Definition: exceptions.h:231
Definition: exceptions.h:216
Definition: exceptions.h:254
Definition: exceptions.h:188