MongoDB C++ Driver mongocxx-3.0.0
Loading...
Searching...
No Matches
mongoc_error.hpp
1// Copyright 2015 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 <bsoncxx/document/value.hpp>
18#include <mongocxx/exception/server_error_code.hpp>
19#include <mongocxx/private/libmongoc.hpp>
20
21#include <mongocxx/config/private/prelude.hpp>
22
23namespace mongocxx {
24MONGOCXX_INLINE_NAMESPACE_BEGIN
25
26inline std::error_code make_error_code(int code, int) {
27 // Domain is ignored. We simply issue the code.
28 return {code, server_error_category()};
29}
30
31inline std::error_code make_error_code(::bson_error_t error) {
32 return make_error_code(error.code, error.domain);
33}
34
35template <typename exception_type>
36void throw_exception(::bson_error_t error) {
37 throw exception_type{make_error_code(error), error.message};
38}
39
40template <typename exception_type>
41void throw_exception(bsoncxx::document::value raw_server_error, ::bson_error_t error) {
42 throw exception_type{make_error_code(error), std::move(raw_server_error), error.message};
43}
44
45MONGOCXX_INLINE_NAMESPACE_END
46} // namespace mongocxx
47
48#include <mongocxx/config/private/postlude.hpp>
A read-only BSON document that owns its underlying buffer.
Definition value.hpp:33