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