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
6
7#include <iosfwd>
8#include <stdexcept>
9#include <string>
10
12
13USERVER_NAMESPACE_BEGIN
14
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
44class ExceptionWithPath : public Exception {
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
55class BadStreamException : public Exception {
56public:
57 explicit BadStreamException(const std::istream& is);
58 explicit BadStreamException(const std::ostream& os);
59};
60
61class TypeMismatchException : public ExceptionWithPath {
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
68class OutOfBoundsException : public ExceptionWithPath {
69public:
70 OutOfBoundsException(size_t index, size_t size, std::string_view path);
71};
72
73class MemberMissingException : public ExceptionWithPath {
74public:
75 explicit MemberMissingException(std::string_view path);
76};
77
78class PathPrefixException : public Exception {
79public:
80 explicit PathPrefixException(std::string_view old_path, std::string_view prefix);
81};
82
83} // namespace formats::yaml
84
85USERVER_NAMESPACE_END