userver: userver/formats/json/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/json/exception.hpp
4/// @brief Exception classes for JSON module
5/// @ingroup userver_universal
6
7#include <iosfwd>
8#include <stdexcept>
9#include <string>
10#include <string_view>
11
12USERVER_NAMESPACE_BEGIN
13
14namespace formats::json {
15
16class Exception : public std::exception {
17public:
18 explicit Exception(std::string msg)
19 : msg_(std::move(msg))
20 {}
21
22 const char* what() const noexcept final { return msg_.c_str(); }
23
24 std::string_view GetMessage() const noexcept { return msg_; }
25
26private:
27 std::string msg_;
28};
29
30class ParseException : public Exception {
31public:
32 using Exception::Exception;
33};
34
36public:
37 explicit ExceptionWithPath(std::string_view msg, std::string_view path);
38
39 std::string_view GetPath() const noexcept;
40 std::string_view GetMessageWithoutPath() const noexcept;
41
42private:
43 std::size_t path_size_;
44};
45
47public:
48 explicit BadStreamException(const std::istream& is);
49 explicit BadStreamException(const std::ostream& os);
50};
51
53public:
54 TypeMismatchException(int actual, int expected, std::string_view path);
55 std::string_view GetActual() const;
56 std::string_view GetExpected() const;
57
58private:
59 int actual_;
60 int expected_;
61};
62
64public:
65 OutOfBoundsException(size_t index, size_t size, std::string_view path);
66};
67
69public:
70 explicit MemberMissingException(std::string_view path);
71};
72
73/// Conversion error
75public:
76 ConversionException(std::string_view msg, std::string_view path);
77};
78
80public:
81 UnknownDiscriminatorException(std::string_view path, std::string_view discriminator_field);
82};
83
84} // namespace formats::json
85
86USERVER_NAMESPACE_END