userver: userver/formats/json/exception.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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 private:
23 std::string msg_;
24};
25
26class ParseException : public Exception {
27 public:
28 using Exception::Exception;
29};
30
32 public:
33 explicit BadStreamException(const std::istream& is);
34 explicit BadStreamException(const std::ostream& os);
35};
36
38 public:
39 TypeMismatchException(int actual, int expected, const std::string& path);
40 std::string_view GetActual() const;
41 std::string_view GetExpected() const;
42 const std::string& GetPath() const noexcept;
43
44 private:
45 int actual_;
46 int expected_;
47 std::string path_;
48};
49
51 public:
52 OutOfBoundsException(size_t index, size_t size, const std::string& path);
53 const std::string& GetPath() const noexcept;
54
55 private:
56 std::string path_;
57};
58
60 public:
61 explicit MemberMissingException(const std::string& path);
62};
63
64/// Conversion error
66 public:
67 using Exception::Exception;
68};
69
70} // namespace formats::json
71
72USERVER_NAMESPACE_END