// Copyright 2009-present MongoDB, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #pragma once #include // IWYU pragma: export // #include #include #include #include #include namespace bsoncxx { namespace v1 { /// /// Enumeration identifying the source of a @ref bsoncxx::v1 error. /// enum class source_errc { zero, ///< Zero. bsoncxx, ///< From the bsoncxx library. bson, ///< From the bson library. }; /// /// The error category for @ref bsoncxx::v1::source_errc. /// BSONCXX_ABI_EXPORT_CDECL(std::error_category const&) source_error_category(); /// /// Support implicit conversion to `std::error_condition`. /// inline std::error_condition make_error_condition(source_errc code) { return {static_cast(code), v1::source_error_category()}; } /// /// Enumeration identifying the type (cause) of a @ref bsoncxx::v1 error. /// enum class type_errc { zero, ///< Zero. invalid_argument, ///< An invalid argument passed to the throwing function. runtime_error, ///< An erroneous condition was detected at runtime. }; /// /// The error category for @ref bsoncxx::v1::type_errc. /// BSONCXX_ABI_EXPORT_CDECL(std::error_category const&) type_error_category(); /// /// Support implicit conversion to `std::error_condition`. /// inline std::error_condition make_error_condition(type_errc code) { return {static_cast(code), v1::type_error_category()}; } BSONCXX_PRIVATE_WARNINGS_PUSH(); BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4251)); BSONCXX_PRIVATE_WARNINGS_DISABLE(MSVC(4275)); /// /// Base class for all exceptions thrown by @ref bsoncxx::v1. /// /// @par Inherits: /// - `std::system_error` /// class exception : public std::system_error { public: using std::system_error::system_error; private: BSONCXX_ABI_NO_EXPORT virtual void key_function() const; }; BSONCXX_PRIVATE_WARNINGS_POP(); } // namespace v1 } // namespace bsoncxx template <> struct std::is_error_condition_enum : true_type {}; template <> struct std::is_error_condition_enum : true_type {}; #include /// /// @file /// Provides bsoncxx error-handling utilities. ///