userver: userver/formats/bson/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/bson/exception.hpp
4/// @brief BSON-specific exceptions
5
6#include <bson/bson.h>
7
8#include <userver/utils/traceful_exception.hpp>
9
10#include <string>
11
12USERVER_NAMESPACE_BEGIN
13
14namespace formats::bson {
15
16/// Generic BSON-related exception
17class BsonException : public utils::TracefulException {
18 public:
19 BsonException(std::string msg);
20
21 std::string_view GetMessage() const noexcept { return msg_; }
22
23 private:
24 std::string msg_;
25};
26
27/// BSON parsing error
29 public:
30 using BsonException::BsonException;
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
44/// BSON types mismatch error
46 public:
47 TypeMismatchException(bson_type_t actual, bson_type_t expected,
48 std::string_view path);
49};
50
51/// BSON array indexing error
53 public:
54 OutOfBoundsException(size_t index, size_t size, std::string_view path);
55};
56
57/// BSON nonexisting member access error
59 public:
60 explicit MemberMissingException(std::string_view path);
61};
62
63/// Conversion error
65 public:
66 ConversionException(std::string_view msg, std::string_view path);
67};
68
69} // namespace formats::bson
70
71USERVER_NAMESPACE_END