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";
92 const char*
const UNEXPECTED_TOKEN_AFTER_DOC =
"unexpected token after end of document";
93 const char*
const NON_UNIQUE_MAP_KEY =
"map keys must be unique";
96 inline const std::string KEY_NOT_FOUND_WITH_KEY(
97 const T&,
typename disable_if<is_numeric<T>>::type* = 0) {
101 inline const std::string KEY_NOT_FOUND_WITH_KEY(
const std::string& key) {
102 std::stringstream stream;
103 stream << KEY_NOT_FOUND <<
": " << key;
107 inline const std::string KEY_NOT_FOUND_WITH_KEY(
const char* key) {
108 std::stringstream stream;
109 stream << KEY_NOT_FOUND <<
": " << key;
113 template <
typename T>
114 inline const std::string KEY_NOT_FOUND_WITH_KEY(
115 const T& key,
typename enable_if<is_numeric<T>>::type* = 0) {
116 std::stringstream stream;
117 stream << KEY_NOT_FOUND <<
": " << key;
121 template <
typename T>
122 inline const std::string BAD_SUBSCRIPT_WITH_KEY(
123 const T&,
typename disable_if<is_numeric<T>>::type* =
nullptr) {
124 return BAD_SUBSCRIPT;
127 inline const std::string BAD_SUBSCRIPT_WITH_KEY(
const std::string& key) {
128 std::stringstream stream;
129 stream << BAD_SUBSCRIPT <<
" (key: \"" << key <<
"\")";
133 inline const std::string BAD_SUBSCRIPT_WITH_KEY(
const char* key) {
134 std::stringstream stream;
135 stream << BAD_SUBSCRIPT <<
" (key: \"" << key <<
"\")";
139 template <
typename T>
140 inline const std::string BAD_SUBSCRIPT_WITH_KEY(
141 const T& key,
typename enable_if<is_numeric<T>>::type* =
nullptr) {
142 std::stringstream stream;
143 stream << BAD_SUBSCRIPT <<
" (key: \"" << key <<
"\")";
147 inline const std::string INVALID_NODE_WITH_KEY(
const std::string& key) {
148 std::stringstream stream;
152 stream <<
"invalid node; first invalid key: \"" << key <<
"\"";
157 class YAML_CPP_API
Exception :
public std::runtime_error {
160 : std::runtime_error(build_what(mark_, msg_)), mark(mark_), msg(msg_) {}
169 static const std::string build_what(
const Mark& mark,
170 const std::string& msg) {
171 if (mark.is_null()) {
175 std::stringstream output;
176 output <<
"yaml-cpp: error at line " << mark.line + 1 <<
", column " 177 << mark.column + 1 <<
": " << msg;
209 template <
typename T>
217 template <
typename T>
227 template <
typename T>
237 ErrorMsg::INVALID_NODE_WITH_KEY(key)) {}
250 template <
typename T>
266 template <
typename Key>
299 explicit BadFile(
const std::string& filename)
301 std::string(ErrorMsg::BAD_FILE) +
": " + filename) {}
303 ~
BadFile() YAML_CPP_NOEXCEPT
override;
308 template <
typename Key>
317 #if defined(_MSC_VER) 318 #define YAML_ATTRIBUTE_NO_SANITIZE_ADDRESS __declspec(no_sanitize_address) 319 #elif defined(__has_cpp_attribute) && __has_cpp_attribute(gnu::no_sanitize) 320 #define YAML_ATTRIBUTE_NO_SANITIZE_ADDRESS [[gnu::no_sanitize("address")]] 321 #elif defined(__has_cpp_attribute) && __has_cpp_attribute(clang::no_sanitize) 322 #define YAML_ATTRIBUTE_NO_SANITIZE_ADDRESS [[clang::no_sanitize("address")]] 323 #elif defined(__has_attribute) && __has_attribute(no_sanitize) 324 #define YAML_ATTRIBUTE_NO_SANITIZE_ADDRESS \ 325 __attribute__((no_sanitize("address"))) 326 #elif defined(__has_attribute) && __has_attribute(no_sanitize_address) 327 #define YAML_ATTRIBUTE_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address)) 329 #define YAML_ATTRIBUTE_NO_SANITIZE_ADDRESS 332 #endif // EXCEPTIONS_H_62B23520_7C8E_11DE_8A39_0800200C9A66 Definition: exceptions.h:281
Definition: exceptions.h:199
Definition: exceptions.h:289
Definition: exceptions.h:264
Definition: exceptions.h:297
Definition: exceptions.h:273
Definition: exceptions.h:242
Definition: exceptions.h:182
Definition: exceptions.h:251
Definition: exceptions.h:207
Definition: exceptions.h:157
Definition: exceptions.h:306
Definition: exceptions.h:233
Definition: exceptions.h:218
Definition: exceptions.h:256
Definition: exceptions.h:190