boost_sqlite 1
A sqlite C++ library
Loading...
Searching...
No Matches
exception.hpp
1// Copyright (c) 2023 Klemens D. Morgenstern
2//
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5#ifndef BOOST_SQLITE_DETAIL_EXCEPTION_HPP
6#define BOOST_SQLITE_DETAIL_EXCEPTION_HPP
7
8#include <boost/sqlite/detail/config.hpp>
9#include <boost/sqlite/error.hpp>
10
11BOOST_SQLITE_BEGIN_NAMESPACE
12namespace detail
13{
14
15BOOST_SQLITE_DECL
16BOOST_NORETURN void throw_error_code(const boost::system::error_code & ec,
17 const boost::source_location & loc = BOOST_CURRENT_LOCATION);
18
19BOOST_SQLITE_DECL
20BOOST_NORETURN void throw_error_code(const boost::system::error_code & ec,
21 const error_info & ei,
22 const boost::source_location & loc = BOOST_CURRENT_LOCATION);
23
24BOOST_SQLITE_DECL
25BOOST_NORETURN void throw_out_of_range(const char * msg,
26 const boost::source_location & loc);
27
28BOOST_SQLITE_DECL
29BOOST_NORETURN void throw_invalid_argument(const char * msg,
30 const boost::source_location & loc);
31
32inline core::string_view get_message(const system::system_error & se)
33{
34 auto ec_len = se.code().what().size();
35 auto se_len = std::strlen(se.what());
36
37 if (ec_len == se_len)
38 return core::string_view();
39 else
40 return core::string_view(se.what(), se_len - (ec_len + 2));
41}
42
43
44}
45BOOST_SQLITE_END_NAMESPACE
46
47
48#endif //BOOST_SQLITE_DETAIL_EXCEPTION_HPP