Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:19:38

0001 //
0002 // Copyright (c) 2019-2023 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 
0008 #ifndef BOOST_MYSQL_ERROR_WITH_DIAGNOSTICS_HPP
0009 #define BOOST_MYSQL_ERROR_WITH_DIAGNOSTICS_HPP
0010 
0011 #include <boost/mysql/diagnostics.hpp>
0012 #include <boost/mysql/error_code.hpp>
0013 
0014 #include <boost/system/system_error.hpp>
0015 
0016 namespace boost {
0017 namespace mysql {
0018 
0019 /**
0020  * \brief A system_error with an embedded diagnostics object.
0021  * \details
0022  * Like `boost::system::system_error`, but adds a \ref diagnostics member
0023  * containing additional information.
0024  */
0025 class error_with_diagnostics : public boost::system::system_error
0026 {
0027     diagnostics diag_;
0028 
0029     static boost::system::system_error create_base(const error_code& err, const diagnostics& diag)
0030     {
0031         return diag.client_message().empty() ? boost::system::system_error(err)
0032                                              : boost::system::system_error(err, diag.client_message());
0033     }
0034 
0035 public:
0036     /// Initializing constructor.
0037     error_with_diagnostics(const error_code& err, const diagnostics& diag)
0038         : boost::system::system_error(create_base(err, diag)), diag_(diag)
0039     {
0040     }
0041 
0042     /**
0043      * \brief Retrieves the server diagnostics embedded in this object.
0044      * \par Exception safety
0045      * No-throw guarantee.
0046      *
0047      * \par Object lifetimes
0048      * The returned reference is valid as long as `*this` is alive.
0049      */
0050     const diagnostics& get_diagnostics() const noexcept { return diag_; }
0051 };
0052 
0053 }  // namespace mysql
0054 }  // namespace boost
0055 
0056 #endif