MongoDB C++ Driver 4.2.0
Loading...
Searching...
No Matches
exception.hpp
Go to the documentation of this file.
1// Copyright 2009-present MongoDB, Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#include <mongocxx/v1/exception-fwd.hpp> // IWYU pragma: export
18
19//
20
22
25
27
28#include <memory>
29#include <system_error>
30#include <type_traits>
31
32namespace mongocxx {
33namespace v1 {
34
47
54
60inline std::error_condition make_error_condition(source_errc code) {
61 return {static_cast<int>(code), v1::source_error_category()};
62}
63
74
80MONGOCXX_ABI_EXPORT_CDECL(std::error_category const&) type_error_category();
81
87inline std::error_condition make_error_condition(type_errc code) {
88 return {static_cast<int>(code), v1::type_error_category()};
89}
90
91BSONCXX_PRIVATE_WARNINGS_PUSH();
92BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4251));
93BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4275));
94
103class exception : public std::system_error {
104 private:
105 class impl;
106 std::shared_ptr<impl> _impl;
107
108 public:
115
116 class internal;
117
118 private:
119 MONGOCXX_ABI_NO_EXPORT /* explicit(false) */
120 exception(std::error_code ec, char const* message, std::unique_ptr<impl> impl);
121
122 MONGOCXX_ABI_NO_EXPORT /* explicit(false) */
123 exception(std::error_code ec, std::unique_ptr<impl> impl);
124
125 MONGOCXX_ABI_NO_EXPORT virtual void key_function() const;
126};
127
128BSONCXX_PRIVATE_WARNINGS_POP();
129
130} // namespace v1
131} // namespace mongocxx
132
133template <>
134struct std::is_error_condition_enum<mongocxx::v1::source_errc> : true_type {};
135
136template <>
137struct std::is_error_condition_enum<mongocxx::v1::type_errc> : true_type {};
138
140
For internal use only!
A polyfill for std::string_view.
Definition string_view.hpp:412
bool has_error_label(bsoncxx::v1::stdx::string_view label) const
Return true if this exception contains the specified error label.
Provides macros to control the set of symbols exported in the ABI.
#define MONGOCXX_ABI_CDECL
Expands to __cdecl when built with MSVC on Windows.
Definition export.hpp:49
#define MONGOCXX_ABI_NO_EXPORT
Excludes the associated entity from being part of the ABI.
Definition export.hpp:20
#define MONGOCXX_ABI_EXPORT_CDECL(...)
Equivalent to MONGOCXX_ABI_EXPORT with MONGOCXX_ABI_CDECL.
Definition export.hpp:52
The mongocxx v1 macro guard postlude header.
The mongocxx v1 macro guard prelude header.
Declares mongocxx error-handling utilities.
Declares entities whose ABI stability is guaranteed for documented symbols.
source_errc
Enumeration identifying the source of a mongocxx::v1 error.
Definition exception.hpp:40
@ mongocrypt
From the mongocrypt library.
Definition exception.hpp:44
@ mongoc
From the mongoc library.
Definition exception.hpp:43
@ server
From the MongoDB server.
Definition exception.hpp:45
@ zero
Zero.
Definition exception.hpp:41
std::error_condition make_error_condition(source_errc code)
Support implicit conversion to std::error_condition.
Definition exception.hpp:60
type_errc
Enumeration identifying the type (cause) of a mongocxx::v1 error.
Definition exception.hpp:69
@ runtime_error
An erroneous condition was detected at runtime.
Definition exception.hpp:72
@ invalid_argument
An invalid argument passed to the throwing function.
Definition exception.hpp:71
std::error_category const & type_error_category()
The error category for mongocxx::v1::type_errc.
std::error_category const & source_error_category()
The error category for mongocxx::v1::source_errc.
The top-level namespace within which all mongocxx library entities are declared.
Provides std::string_view-related polyfills for library API usage.