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;
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 ~ParseException() override;
34};
35
37public:
38 explicit ExceptionWithPath(std::string_view msg, std::string_view path);
39
40 std::string_view GetPath() const noexcept;
41 std::string_view GetMessageWithoutPath() const noexcept;
42
43private:
44 std::size_t path_size_;
45};
46
48public:
49 explicit BadStreamException(const std::istream& is);
50 explicit BadStreamException(const std::ostream& os);
51};
52
54public:
55 TypeMismatchException(int actual, int expected, std::string_view path);
56 std::string_view GetActual() const;
57 std::string_view GetExpected() const;
58
59private:
60 int actual_;
61 int expected_;
62};
63
65public:
66 OutOfBoundsException(size_t index, size_t size, std::string_view path);
67};
68
70public:
71 explicit MemberMissingException(std::string_view path);
72};
73
74/// Conversion error
76public:
77 ConversionException(std::string_view msg, std::string_view path);
78};
79
81public:
82 UnknownDiscriminatorException(std::string_view path, std::string_view discriminator_field);
83};
84
85} // namespace formats::json
86
87USERVER_NAMESPACE_END