userver: userver/formats/yaml/exception.hpp Source File
Loading...
Searching...
No Matches
exception.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/formats/yaml/exception.hpp
4/// @brief Exception classes for YAML module
5/// @ingroup userver_universal
6
7#include <iosfwd>
8#include <stdexcept>
9#include <string>
10
11#include <userver/formats/yaml/types.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15/// @brief YAML document model (`formats::yaml::Value`) and helpers.
16namespace formats::yaml {
17
18class Exception : public std::exception {
19public:
20 explicit Exception(std::string msg)
21 : msg_(std::move(msg))
22 {}
23
24 const char* what() const noexcept final;
25
26 std::string_view GetMessage() const noexcept { return msg_; }
27
28private:
29 std::string msg_;
30};
31
32class ParseException : public Exception {
33public:
34 using Exception::Exception;
35
36 ParseException(const ParseException&) = default;
37 ParseException(ParseException&&) = default;
38 ParseException& operator=(const ParseException&) = default;
39 ParseException& operator=(ParseException&&) = default;
40
41 ~ParseException() override;
42};
43
45public:
46 explicit ExceptionWithPath(std::string_view msg, std::string_view path);
47
48 std::string_view GetPath() const noexcept;
49 std::string_view GetMessageWithoutPath() const noexcept;
50
51private:
52 std::size_t path_size_;
53};
54
56public:
57 explicit BadStreamException(const std::istream& is);
58 explicit BadStreamException(const std::ostream& os);
59};
60
62public:
63 TypeMismatchException(Type actual, Type expected, std::string_view path);
64 TypeMismatchException(int actual, int expected, std::string_view path);
65 TypeMismatchException(const YAML::Node& value, std::string_view expected_type, std::string_view path);
66};
67
69public:
70 OutOfBoundsException(size_t index, size_t size, std::string_view path);
71};
72
74public:
75 explicit MemberMissingException(std::string_view path);
76};
77
79public:
80 explicit PathPrefixException(std::string_view old_path, std::string_view prefix);
81};
82
83} // namespace formats::yaml
84
85USERVER_NAMESPACE_END