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) : msg_(std::move(msg)) {}
19
20 const char* what() const noexcept final { return msg_.c_str(); }
21
22 std::string_view GetMessage() const noexcept { return msg_; }
23
24private:
25 std::string msg_;
26};
27
28class ParseException : public Exception {
29public:
30 using Exception::Exception;
31};
32
34public:
35 explicit ExceptionWithPath(std::string_view msg, std::string_view path);
36
37 std::string_view GetPath() const noexcept;
38 std::string_view GetMessageWithoutPath() const noexcept;
39
40private:
41 std::size_t path_size_;
42};
43
45public:
46 explicit BadStreamException(const std::istream& is);
47 explicit BadStreamException(const std::ostream& os);
48};
49
51public:
52 TypeMismatchException(int actual, int expected, std::string_view path);
53 std::string_view GetActual() const;
54 std::string_view GetExpected() const;
55
56private:
57 int actual_;
58 int expected_;
59};
60
62public:
63 OutOfBoundsException(size_t index, size_t size, std::string_view path);
64};
65
67public:
68 explicit MemberMissingException(std::string_view path);
69};
70
71/// Conversion error
73public:
74 ConversionException(std::string_view msg, std::string_view path);
75};
76
78public:
79 UnknownDiscriminatorException(std::string_view path, std::string_view discriminator_field);
80};
81
82} // namespace formats::json
83
84USERVER_NAMESPACE_END