1  
//
1  
//
2  
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
2  
// Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
3  
//
3  
//
4  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
4  
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5  
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6  
//
6  
//
7  
// Official repository: https://github.com/cppalliance/http
7  
// Official repository: https://github.com/cppalliance/http
8  
//
8  
//
9  

9  

10  
#include <boost/http/detail/except.hpp>
10  
#include <boost/http/detail/except.hpp>
11  
#include <boost/system/system_error.hpp>
11  
#include <boost/system/system_error.hpp>
12  
#include <boost/version.hpp>
12  
#include <boost/version.hpp>
13  
#include <boost/throw_exception.hpp>
13  
#include <boost/throw_exception.hpp>
14  
#include <stdexcept>
14  
#include <stdexcept>
15  
#include <typeinfo>
15  
#include <typeinfo>
16  

16  

17  
namespace boost {
17  
namespace boost {
18  
namespace http {
18  
namespace http {
19  
namespace detail {
19  
namespace detail {
20  

20  

21  
void
21  
void
22  
throw_bad_alloc(
22  
throw_bad_alloc(
23  
    source_location const& loc)
23  
    source_location const& loc)
24  
{
24  
{
25  
    throw_exception(
25  
    throw_exception(
26  
        std::bad_alloc(), loc);
26  
        std::bad_alloc(), loc);
27  
}
27  
}
28  

28  

29  
void
29  
void
30  
throw_bad_typeid(
30  
throw_bad_typeid(
31  
    source_location const& loc)
31  
    source_location const& loc)
32  
{
32  
{
33  
    throw_exception(
33  
    throw_exception(
34  
        std::bad_typeid(), loc);
34  
        std::bad_typeid(), loc);
35  
}
35  
}
36  

36  

37  
void
37  
void
38  
throw_invalid_argument(
38  
throw_invalid_argument(
39  
    source_location const& loc)
39  
    source_location const& loc)
40  
{
40  
{
41  
    throw_exception(
41  
    throw_exception(
42  
        std::invalid_argument(
42  
        std::invalid_argument(
43  
            "invalid argument"),
43  
            "invalid argument"),
44  
        loc);
44  
        loc);
45  
}
45  
}
46  

46  

47  
void
47  
void
48  
throw_invalid_argument(
48  
throw_invalid_argument(
49  
    char const* what,
49  
    char const* what,
50  
    source_location const& loc)
50  
    source_location const& loc)
51  
{
51  
{
52  
    throw_exception(
52  
    throw_exception(
53  
        std::invalid_argument(what), loc);
53  
        std::invalid_argument(what), loc);
54  
}
54  
}
55  

55  

56  
void
56  
void
57  
throw_length_error(
57  
throw_length_error(
58  
    source_location const& loc)
58  
    source_location const& loc)
59  
{
59  
{
60  
    throw_exception(
60  
    throw_exception(
61  
        std::length_error(
61  
        std::length_error(
62  
            "length error"), loc);
62  
            "length error"), loc);
63  
}
63  
}
64  

64  

65  
void
65  
void
66  
throw_length_error(
66  
throw_length_error(
67  
    char const* what,
67  
    char const* what,
68  
    source_location const& loc)
68  
    source_location const& loc)
69  
{
69  
{
70  
    throw_exception(
70  
    throw_exception(
71  
        std::length_error(what), loc);
71  
        std::length_error(what), loc);
72  
}
72  
}
73  

73  

74  
void
74  
void
75  
throw_logic_error(
75  
throw_logic_error(
76  
    source_location const& loc)
76  
    source_location const& loc)
77  
{
77  
{
78  
    throw_exception(
78  
    throw_exception(
79  
        std::logic_error(
79  
        std::logic_error(
80  
            "logic error"),
80  
            "logic error"),
81  
        loc);
81  
        loc);
82  
}
82  
}
83  

83  

84  
void
84  
void
85  
throw_out_of_range(
85  
throw_out_of_range(
86  
    source_location const& loc)
86  
    source_location const& loc)
87  
{
87  
{
88  
    throw_exception(
88  
    throw_exception(
89  
        std::out_of_range("out of range"), loc);
89  
        std::out_of_range("out of range"), loc);
90  
}
90  
}
91  

91  

92  
void
92  
void
93  
throw_runtime_error(
93  
throw_runtime_error(
94  
    char const* what,
94  
    char const* what,
95  
    source_location const& loc)
95  
    source_location const& loc)
96  
{
96  
{
97  
    throw_exception(
97  
    throw_exception(
98  
        std::runtime_error(what), loc);
98  
        std::runtime_error(what), loc);
99  
}
99  
}
100  

100  

101  
void
101  
void
102  
throw_system_error(
102  
throw_system_error(
103  
    system::error_code const& ec,
103  
    system::error_code const& ec,
104  
    source_location const& loc)
104  
    source_location const& loc)
105  
{
105  
{
106  
    throw_exception(
106  
    throw_exception(
107  
        system::system_error(ec), loc);
107  
        system::system_error(ec), loc);
108  
}
108  
}
109  

109  

110  
void
110  
void
111  
throw_system_error(
111  
throw_system_error(
112  
    error e,
112  
    error e,
113  
    source_location const& loc)
113  
    source_location const& loc)
114  
{
114  
{
115  
    throw_exception(
115  
    throw_exception(
116  
        system::system_error(e), loc);
116  
        system::system_error(e), loc);
117  
}
117  
}
118  

118  

119  
} // detail
119  
} // detail
120  
} // http
120  
} // http
121  
} // boost
121  
} // boost