Use BOOST_THROW_EXCEPTION

fix #370
This commit is contained in:
Vinnie Falco
2017-05-22 15:30:12 -07:00
parent 167e168d43
commit 3543b4b913
31 changed files with 174 additions and 156 deletions

View File

@@ -1,3 +1,9 @@
Version 44
* Use BOOST_THROW_EXCEPTION
--------------------------------------------------------------------------------
Version 43 Version 43
* Require Boost 1.64.0 * Require Boost 1.64.0

View File

@@ -9,6 +9,7 @@
#define BEAST_TEST_FAIL_COUNTER_HPP #define BEAST_TEST_FAIL_COUNTER_HPP
#include <beast/core/error.hpp> #include <beast/core/error.hpp>
#include <boost/throw_exception.hpp>
namespace beast { namespace beast {
namespace test { namespace test {
@@ -114,7 +115,7 @@ public:
if(n_ > 0) if(n_ > 0)
--n_; --n_;
if(! n_) if(! n_)
throw system_error{ec_}; BOOST_THROW_EXCEPTION(system_error{ec_});
} }
/// Set an error code on the Nth failure /// Set an error code on the Nth failure

View File

@@ -15,6 +15,7 @@
#include <beast/websocket/teardown.hpp> #include <beast/websocket/teardown.hpp>
#include <boost/asio/buffer.hpp> #include <boost/asio/buffer.hpp>
#include <boost/asio/io_service.hpp> #include <boost/asio/io_service.hpp>
#include <boost/throw_exception.hpp>
#include <string> #include <string>
namespace beast { namespace beast {
@@ -59,7 +60,7 @@ public:
error_code ec; error_code ec;
auto const n = read_some(buffers, ec); auto const n = read_some(buffers, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
return n; return n;
} }
@@ -104,7 +105,7 @@ public:
error_code ec; error_code ec;
auto const n = write_some(buffers, ec); auto const n = write_some(buffers, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
return n; return n;
} }

View File

@@ -15,6 +15,7 @@
#include <beast/websocket/teardown.hpp> #include <beast/websocket/teardown.hpp>
#include <boost/asio/buffer.hpp> #include <boost/asio/buffer.hpp>
#include <boost/asio/io_service.hpp> #include <boost/asio/io_service.hpp>
#include <boost/throw_exception.hpp>
#include <string> #include <string>
namespace beast { namespace beast {
@@ -57,7 +58,7 @@ public:
error_code ec; error_code ec;
auto const n = read_some(buffers, ec); auto const n = read_some(buffers, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
return n; return n;
} }
@@ -102,7 +103,7 @@ public:
error_code ec; error_code ec;
auto const n = write_some(buffers, ec); auto const n = write_some(buffers, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
return n; return n;
} }

View File

@@ -15,6 +15,7 @@
#include <beast/websocket/teardown.hpp> #include <beast/websocket/teardown.hpp>
#include <boost/asio/buffer.hpp> #include <boost/asio/buffer.hpp>
#include <boost/asio/io_service.hpp> #include <boost/asio/io_service.hpp>
#include <boost/throw_exception.hpp>
#include <string> #include <string>
namespace beast { namespace beast {
@@ -50,7 +51,7 @@ public:
error_code ec; error_code ec;
auto const n = read_some(buffers, ec); auto const n = read_some(buffers, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
return n; return n;
} }
@@ -83,7 +84,7 @@ public:
error_code ec; error_code ec;
auto const n = write_some(buffers, ec); auto const n = write_some(buffers, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
return n; return n;
} }

View File

@@ -11,6 +11,7 @@
#include <beast/unit_test/runner.hpp> #include <beast/unit_test/runner.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/throw_exception.hpp>
#include <ostream> #include <ostream>
#include <sstream> #include <sstream>
#include <string> #include <string>
@@ -551,7 +552,7 @@ fail(std::string const& reason)
if(abort_) if(abort_)
{ {
aborted_ = true; aborted_ = true;
throw abort_exception(); BOOST_THROW_EXCEPTION(abort_exception());
} }
} }
@@ -569,7 +570,7 @@ suite::
propagate_abort() propagate_abort()
{ {
if(abort_ && aborted_) if(abort_ && aborted_)
throw abort_exception(); BOOST_THROW_EXCEPTION(abort_exception());
} }
template<class> template<class>

View File

@@ -11,6 +11,8 @@
#include <beast/core/error.hpp> #include <beast/core/error.hpp>
#include <beast/core/type_traits.hpp> #include <beast/core/type_traits.hpp>
#include <boost/asio/buffer.hpp> #include <boost/asio/buffer.hpp>
#include <boost/throw_exception.hpp>
// BOOST_THROW_EXCEPTION(
#include <ostream> #include <ostream>
namespace beast { namespace beast {
@@ -56,7 +58,7 @@ write_some(ConstBufferSequence const& buffers)
error_code ec; error_code ec;
auto const n = write_some(buffers, ec); auto const n = write_some(buffers, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
return n; return n;
} }

View File

@@ -14,7 +14,6 @@
#include <iterator> #include <iterator>
#include <tuple> #include <tuple>
#include <type_traits> #include <type_traits>
#include <stdexcept>
#include <string> #include <string>
namespace beast { namespace beast {
@@ -88,18 +87,6 @@ struct repeat_tuple<0, T>
using type = std::tuple<>; using type = std::tuple<>;
}; };
template<class Exception>
Exception
make_exception(char const* reason, char const* file, int line)
{
char const* n = file;
for(auto p = file; *p; ++p)
if(*p == '\\' || *p == '/')
n = p + 1;
return Exception{std::string(reason) + " (" +
n + ":" + std::to_string(line) + ")"};
}
template<class R, class C, class ...A> template<class R, class C, class ...A>
auto auto
is_invocable_test(C&& c, int, A&& ...a) is_invocable_test(C&& c, int, A&& ...a)

View File

@@ -10,6 +10,7 @@
#include <beast/core/detail/type_traits.hpp> #include <beast/core/detail/type_traits.hpp>
#include <boost/asio/buffer.hpp> #include <boost/asio/buffer.hpp>
#include <boost/throw_exception.hpp>
#include <array> #include <array>
#include <cstdint> #include <cstdint>
#include <iterator> #include <iterator>
@@ -215,8 +216,8 @@ private:
reference reference
dereference(C<sizeof...(Bn)> const&) const dereference(C<sizeof...(Bn)> const&) const
{ {
throw detail::make_exception<std::logic_error>( BOOST_THROW_EXCEPTION(std::logic_error{
"invalid iterator", __FILE__, __LINE__); "invalid iterator"});
} }
template<std::size_t I> template<std::size_t I>
@@ -232,8 +233,8 @@ private:
void void
increment(C<sizeof...(Bn)> const&) increment(C<sizeof...(Bn)> const&)
{ {
throw detail::make_exception<std::logic_error>( BOOST_THROW_EXCEPTION(std::logic_error{
"invalid iterator", __FILE__, __LINE__); "invalid iterator"});
} }
template<std::size_t I> template<std::size_t I>
@@ -274,8 +275,8 @@ private:
--iter<I>(); --iter<I>();
return; return;
} }
throw detail::make_exception<std::logic_error>( BOOST_THROW_EXCEPTION(std::logic_error{
"invalid iterator", __FILE__, __LINE__); "invalid iterator"});
} }
template<std::size_t I> template<std::size_t I>

View File

@@ -15,6 +15,7 @@
#include <boost/asio/handler_alloc_hook.hpp> #include <boost/asio/handler_alloc_hook.hpp>
#include <boost/asio/handler_continuation_hook.hpp> #include <boost/asio/handler_continuation_hook.hpp>
#include <boost/asio/handler_invoke_hook.hpp> #include <boost/asio/handler_invoke_hook.hpp>
#include <boost/throw_exception.hpp>
namespace beast { namespace beast {
@@ -197,7 +198,7 @@ read_some(
error_code ec; error_code ec;
auto n = read_some(buffers, ec); auto n = read_some(buffers, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
return n; return n;
} }

View File

@@ -10,6 +10,7 @@
#include <beast/core/detail/type_traits.hpp> #include <beast/core/detail/type_traits.hpp>
#include <boost/asio/buffer.hpp> #include <boost/asio/buffer.hpp>
#include <boost/throw_exception.hpp>
#include <algorithm> #include <algorithm>
#include <cstring> #include <cstring>
#include <iterator> #include <iterator>
@@ -414,8 +415,8 @@ buffers_adapter<MutableBufferSequence>::prepare(std::size_t n) ->
} }
} }
if(n > 0) if(n > 0)
throw detail::make_exception<std::length_error>( BOOST_THROW_EXCEPTION(std::length_error{
"no space", __FILE__, __LINE__); "no space"});
return mutable_buffers_type{*this}; return mutable_buffers_type{*this};
} }

View File

@@ -9,6 +9,7 @@
#define BEAST_IMPL_FLAT_BUFFER_HPP #define BEAST_IMPL_FLAT_BUFFER_HPP
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/throw_exception.hpp>
#include <stdexcept> #include <stdexcept>
namespace beast { namespace beast {
@@ -211,8 +212,8 @@ prepare(std::size_t n) ->
} }
// enforce maximum capacity // enforce maximum capacity
if(n > max_ - len) if(n > max_ - len)
throw std::length_error{ BOOST_THROW_EXCEPTION(std::length_error{
"basic_flat_buffer overflow"}; "basic_flat_buffer overflow"});
// allocate a new buffer // allocate a new buffer
auto const new_size = (std::min)(max_, auto const new_size = (std::min)(max_,
std::max<std::size_t>( std::max<std::size_t>(
@@ -257,8 +258,8 @@ reserve(std::size_t n)
if(n <= capacity()) if(n <= capacity())
return; return;
if(n > max_) if(n > max_)
throw std::length_error{ BOOST_THROW_EXCEPTION(std::length_error{
"basic_flat_buffer overflow"}; "basic_flat_buffer overflow"});
auto const new_size = (std::min)(max_, auto const new_size = (std::min)(max_,
std::max<std::size_t>( std::max<std::size_t>(
detail::next_pow2(n), min_size)); detail::next_pow2(n), min_size));

View File

@@ -10,6 +10,7 @@
#include <beast/core/detail/type_traits.hpp> #include <beast/core/detail/type_traits.hpp>
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/throw_exception.hpp>
#include <algorithm> #include <algorithm>
#include <exception> #include <exception>
#include <sstream> #include <sstream>
@@ -523,8 +524,8 @@ basic_multi_buffer<Allocator>::basic_multi_buffer(
, alloc_size_(alloc_size) , alloc_size_(alloc_size)
{ {
if(alloc_size <= 0) if(alloc_size <= 0)
throw detail::make_exception<std::invalid_argument>( BOOST_THROW_EXCEPTION(std::invalid_argument{
"invalid alloc_size", __FILE__, __LINE__); "invalid alloc_size"});
} }
template<class Allocator> template<class Allocator>

View File

@@ -10,6 +10,7 @@
#include <beast/core/detail/type_traits.hpp> #include <beast/core/detail/type_traits.hpp>
#include <boost/asio/buffer.hpp> #include <boost/asio/buffer.hpp>
#include <boost/throw_exception.hpp>
#include <algorithm> #include <algorithm>
#include <cstring> #include <cstring>
#include <iterator> #include <iterator>
@@ -295,8 +296,8 @@ static_buffer::prepare(std::size_t n) ->
mutable_buffers_type mutable_buffers_type
{ {
if(n > static_cast<std::size_t>(end_ - out_)) if(n > static_cast<std::size_t>(end_ - out_))
throw detail::make_exception<std::length_error>( BOOST_THROW_EXCEPTION(std::length_error{
"static_buffer overflow", __FILE__, __LINE__); "static_buffer overflow"});
last_ = out_ + n; last_ = out_ + n;
return mutable_buffers_type{out_, n}; return mutable_buffers_type{out_, n};
} }

View File

@@ -9,6 +9,7 @@
#define BEAST_IMPL_STATIC_STRING_IPP #define BEAST_IMPL_STATIC_STRING_IPP
#include <beast/core/detail/type_traits.hpp> #include <beast/core/detail/type_traits.hpp>
#include <boost/throw_exception.hpp>
namespace beast { namespace beast {
@@ -119,8 +120,8 @@ assign(size_type count, CharT ch) ->
static_string& static_string&
{ {
if(count > max_size()) if(count > max_size())
throw detail::make_exception<std::length_error>( BOOST_THROW_EXCEPTION(std::length_error{
"count > max_size()", __FILE__, __LINE__); "count > max_size()"});
n_ = count; n_ = count;
Traits::assign(&s_[0], n_, ch); Traits::assign(&s_[0], n_, ch);
term(); term();
@@ -157,8 +158,8 @@ assign(CharT const* s, size_type count) ->
static_string& static_string&
{ {
if(count > max_size()) if(count > max_size())
throw detail::make_exception<std::length_error>( BOOST_THROW_EXCEPTION(std::length_error{
"count > max_size()", __FILE__, __LINE__); "count > max_size()"});
n_ = count; n_ = count;
Traits::copy(&s_[0], s, n_); Traits::copy(&s_[0], s, n_);
term(); term();
@@ -174,8 +175,8 @@ assign(InputIt first, InputIt last) ->
{ {
std::size_t const n = std::distance(first, last); std::size_t const n = std::distance(first, last);
if(n > max_size()) if(n > max_size())
throw detail::make_exception<std::length_error>( BOOST_THROW_EXCEPTION(std::length_error{
"n > max_size()", __FILE__, __LINE__); "n > max_size()"});
n_ = n; n_ = n;
for(auto it = &s_[0]; first != last; ++it, ++first) for(auto it = &s_[0]; first != last; ++it, ++first)
Traits::assign(*it, *first); Traits::assign(*it, *first);
@@ -193,8 +194,8 @@ assign(T const& t, size_type pos, size_type count) ->
{ {
auto const sv = string_view_type(t).substr(pos, count); auto const sv = string_view_type(t).substr(pos, count);
if(sv.size() > max_size()) if(sv.size() > max_size())
throw detail::make_exception<std::length_error>( BOOST_THROW_EXCEPTION(std::length_error{
"sv.size() > max_size()", __FILE__, __LINE__); "sv.size() > max_size()"});
n_ = sv.size(); n_ = sv.size();
Traits::copy(&s_[0], &sv[0], n_); Traits::copy(&s_[0], &sv[0], n_);
term(); term();
@@ -212,8 +213,8 @@ at(size_type pos) ->
reference reference
{ {
if(pos >= size()) if(pos >= size())
throw detail::make_exception<std::out_of_range>( BOOST_THROW_EXCEPTION(std::out_of_range{
"pos >= size()", __FILE__, __LINE__); "pos >= size()"});
return s_[pos]; return s_[pos];
} }
@@ -224,8 +225,8 @@ at(size_type pos) const ->
const_reference const_reference
{ {
if(pos >= size()) if(pos >= size())
throw detail::make_exception<std::out_of_range>( BOOST_THROW_EXCEPTION(std::out_of_range{
"pos >= size()", __FILE__, __LINE__); "pos >= size()"});
return s_[pos]; return s_[pos];
} }
@@ -239,8 +240,8 @@ static_string<N, CharT, Traits>::
reserve(std::size_t n) reserve(std::size_t n)
{ {
if(n > max_size()) if(n > max_size())
throw detail::make_exception<std::length_error>( BOOST_THROW_EXCEPTION(std::length_error{
"n > max_size()", __FILE__, __LINE__); "n > max_size()"});
} }
// //
@@ -263,8 +264,8 @@ insert(size_type index, size_type count, CharT ch) ->
static_string& static_string&
{ {
if(index > size()) if(index > size())
throw detail::make_exception<std::out_of_range>( BOOST_THROW_EXCEPTION(std::out_of_range{
"index > size()", __FILE__, __LINE__); "index > size()"});
insert(begin() + index, count, ch); insert(begin() + index, count, ch);
return *this; return *this;
} }
@@ -276,11 +277,11 @@ insert(size_type index, CharT const* s, size_type count) ->
static_string& static_string&
{ {
if(index > size()) if(index > size())
throw detail::make_exception<std::out_of_range>( BOOST_THROW_EXCEPTION(std::out_of_range{
"index > size()", __FILE__, __LINE__); "index > size()"});
if(size() + count > max_size()) if(size() + count > max_size())
throw detail::make_exception<std::length_error>( BOOST_THROW_EXCEPTION(std::length_error{
"size() + count > max_size()", __FILE__, __LINE__); "size() + count > max_size()"});
Traits::move( Traits::move(
&s_[index + count], &s_[index], size() - index); &s_[index + count], &s_[index], size() - index);
n_ += count; n_ += count;
@@ -309,8 +310,8 @@ insert(const_iterator pos, size_type count, CharT ch) ->
iterator iterator
{ {
if(size() + count > max_size()) if(size() + count > max_size())
throw detail::make_exception<std::length_error>( BOOST_THROW_EXCEPTION(std::length_error{
"size() + count() > max_size()", __FILE__, __LINE__); "size() + count() > max_size()"});
auto const index = pos - &s_[0]; auto const index = pos - &s_[0];
Traits::move( Traits::move(
&s_[index + count], &s_[index], size() - index); &s_[index + count], &s_[index], size() - index);
@@ -331,8 +332,8 @@ insert(const_iterator pos, InputIt first, InputIt last) ->
{ {
std::size_t const count = std::distance(first, last); std::size_t const count = std::distance(first, last);
if(size() + count > max_size()) if(size() + count > max_size())
throw detail::make_exception<std::length_error>( BOOST_THROW_EXCEPTION(std::length_error{
"size() + count > max_size()", __FILE__, __LINE__); "size() + count > max_size()"});
std::size_t const index = pos - begin(); std::size_t const index = pos - begin();
Traits::move( Traits::move(
&s_[index + count], &s_[index], size() - index); &s_[index + count], &s_[index], size() - index);
@@ -367,8 +368,8 @@ erase(size_type index, size_type count) ->
static_string& static_string&
{ {
if(index > size()) if(index > size())
throw detail::make_exception<std::out_of_range>( BOOST_THROW_EXCEPTION(std::out_of_range{
"index > size()", __FILE__, __LINE__); "index > size()"});
auto const n = (std::min)(count, size() - index); auto const n = (std::min)(count, size() - index);
Traits::move( Traits::move(
&s_[index], &s_[index + n], size() - (index + n) + 1); &s_[index], &s_[index + n], size() - (index + n) + 1);
@@ -403,8 +404,8 @@ static_string<N, CharT, Traits>::
push_back(CharT ch) push_back(CharT ch)
{ {
if(size() >= max_size()) if(size() >= max_size())
throw detail::make_exception<std::length_error>( BOOST_THROW_EXCEPTION(std::length_error{
"size() >= max_size()", __FILE__, __LINE__); "size() >= max_size()"});
Traits::assign(s_[n_++], ch); Traits::assign(s_[n_++], ch);
term(); term();
} }
@@ -419,8 +420,8 @@ append(static_string<M, CharT, Traits> const& str,
{ {
// Valid range is [0, size) // Valid range is [0, size)
if(pos >= str.size()) if(pos >= str.size())
throw detail::make_exception<std::out_of_range>( BOOST_THROW_EXCEPTION(std::out_of_range{
"pos > str.size()", __FILE__, __LINE__); "pos > str.size()"});
string_view_type const ss{&str.s_[pos], string_view_type const ss{&str.s_[pos],
(std::min)(count, str.size() - pos)}; (std::min)(count, str.size() - pos)};
insert(size(), ss.data(), ss.size()); insert(size(), ss.data(), ss.size());
@@ -434,8 +435,8 @@ substr(size_type pos, size_type count) const ->
string_view_type string_view_type
{ {
if(pos > size()) if(pos > size())
throw detail::make_exception<std::out_of_range>( BOOST_THROW_EXCEPTION(std::out_of_range{
"pos > size()", __FILE__, __LINE__); "pos > size()"});
return{&s_[pos], (std::min)(count, size() - pos)}; return{&s_[pos], (std::min)(count, size() - pos)};
} }
@@ -456,8 +457,8 @@ static_string<N, CharT, Traits>::
resize(std::size_t n) resize(std::size_t n)
{ {
if(n > max_size()) if(n > max_size())
throw detail::make_exception<std::length_error>( BOOST_THROW_EXCEPTION(std::length_error{
"n > max_size()", __FILE__, __LINE__); "n > max_size()"});
n_ = n; n_ = n;
term(); term();
} }
@@ -468,8 +469,8 @@ static_string<N, CharT, Traits>::
resize(std::size_t n, CharT c) resize(std::size_t n, CharT c)
{ {
if(n > max_size()) if(n > max_size())
throw detail::make_exception<std::length_error>( BOOST_THROW_EXCEPTION(std::length_error{
"n > max_size()", __FILE__, __LINE__); "n > max_size()"});
if(n > n_) if(n > n_)
Traits::assign(&s_[n_], n - n_, c); Traits::assign(&s_[n_], n - n_, c);
n_ = n; n_ = n;
@@ -495,11 +496,11 @@ static_string<N, CharT, Traits>::
swap(static_string<M, CharT, Traits>& str) swap(static_string<M, CharT, Traits>& str)
{ {
if(size() > str.max_size()) if(size() > str.max_size())
throw detail::make_exception<std::length_error>( BOOST_THROW_EXCEPTION(std::length_error{
"size() > str.max_size()", __FILE__, __LINE__); "size() > str.max_size()"});
if(str.size() > max_size()) if(str.size() > max_size())
throw detail::make_exception<std::length_error>( BOOST_THROW_EXCEPTION(std::length_error{
"str.size() > max_size()", __FILE__, __LINE__); "str.size() > max_size()"});
static_string tmp(str); static_string tmp(str);
str.n_ = n_; str.n_ = n_;
Traits::copy(&str.s_[0], &s_[0], n_ + 1); Traits::copy(&str.s_[0], &s_[0], n_ + 1);
@@ -526,8 +527,8 @@ static_string<N, CharT, Traits>::
assign_char(CharT ch, std::false_type) -> assign_char(CharT ch, std::false_type) ->
static_string& static_string&
{ {
throw detail::make_exception<std::length_error>( BOOST_THROW_EXCEPTION(std::length_error{
"max_size() == 0", __FILE__, __LINE__); "max_size() == 0"});
} }
namespace detail { namespace detail {

View File

@@ -11,6 +11,7 @@
#include <beast/config.hpp> #include <beast/config.hpp>
#include <beast/http/message.hpp> #include <beast/http/message.hpp>
#include <beast/http/basic_parser.hpp> #include <beast/http/basic_parser.hpp>
#include <boost/throw_exception.hpp>
#include <array> #include <array>
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
@@ -162,8 +163,8 @@ private:
{ {
// Can't write body data with header-only parser! // Can't write body data with header-only parser!
BOOST_ASSERT(false); BOOST_ASSERT(false);
throw std::logic_error{ BOOST_THROW_EXCEPTION(std::logic_error{
"invalid member function call"}; "invalid member function call"});
} }
void void

View File

@@ -16,6 +16,7 @@
#include <beast/core/detail/type_traits.hpp> #include <beast/core/detail/type_traits.hpp>
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <boost/throw_exception.hpp>
#include <stdexcept> #include <stdexcept>
namespace beast { namespace beast {
@@ -134,7 +135,7 @@ prepare_content_length(prepare_info& pi,
error_code ec; error_code ec;
w.init(ec); w.init(ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
pi.content_length = w.content_length(); pi.content_length = w.content_length();
} }
@@ -157,8 +158,6 @@ void
prepare(message<isRequest, Body, Fields>& msg, prepare(message<isRequest, Body, Fields>& msg,
Options&&... options) Options&&... options)
{ {
using beast::detail::make_exception;
// VFALCO TODO // VFALCO TODO
static_assert(is_Body<Body>::value, static_assert(is_Body<Body>::value,
"Body requirements not met"); "Body requirements not met");
@@ -174,16 +173,16 @@ prepare(message<isRequest, Body, Fields>& msg,
std::forward<Options>(options)...); std::forward<Options>(options)...);
if(msg.fields.exists("Connection")) if(msg.fields.exists("Connection"))
throw make_exception<std::invalid_argument>( BOOST_THROW_EXCEPTION(std::invalid_argument{
"prepare called with Connection field set", __FILE__, __LINE__); "prepare called with Connection field set"});
if(msg.fields.exists("Content-Length")) if(msg.fields.exists("Content-Length"))
throw make_exception<std::invalid_argument>( BOOST_THROW_EXCEPTION(std::invalid_argument{
"prepare called with Content-Length field set", __FILE__, __LINE__); "prepare called with Content-Length field set"});
if(token_list{msg.fields["Transfer-Encoding"]}.exists("chunked")) if(token_list{msg.fields["Transfer-Encoding"]}.exists("chunked"))
throw make_exception<std::invalid_argument>( BOOST_THROW_EXCEPTION(std::invalid_argument{
"prepare called with Transfer-Encoding: chunked set", __FILE__, __LINE__); "prepare called with Transfer-Encoding: chunked set"});
if(pi.connection_value != connection::upgrade) if(pi.connection_value != connection::upgrade)
{ {
@@ -254,8 +253,8 @@ prepare(message<isRequest, Body, Fields>& msg,
// rfc7230 6.7. // rfc7230 6.7.
if(msg.version < 11 && token_list{ if(msg.version < 11 && token_list{
msg.fields["Connection"]}.exists("upgrade")) msg.fields["Connection"]}.exists("upgrade"))
throw make_exception<std::invalid_argument>( BOOST_THROW_EXCEPTION(std::invalid_argument{
"invalid version for Connection: upgrade", __FILE__, __LINE__); "invalid version for Connection: upgrade"});
} }
namespace detail { namespace detail {

View File

@@ -20,6 +20,7 @@
#include <boost/asio/handler_invoke_hook.hpp> #include <boost/asio/handler_invoke_hook.hpp>
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <boost/throw_exception.hpp>
namespace beast { namespace beast {
namespace http { namespace http {
@@ -203,7 +204,7 @@ read_some(
auto const bytes_used = auto const bytes_used =
read_some(stream, buffer, parser, ec); read_some(stream, buffer, parser, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
return bytes_used; return bytes_used;
} }
@@ -244,7 +245,7 @@ read(
error_code ec; error_code ec;
read(stream, buffer, parser, ec); read(stream, buffer, parser, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
template< template<
@@ -298,7 +299,7 @@ read(
error_code ec; error_code ec;
beast::http::read(stream, buffer, msg, ec); beast::http::read(stream, buffer, msg, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
template< template<

View File

@@ -21,6 +21,7 @@
#include <boost/asio/handler_continuation_hook.hpp> #include <boost/asio/handler_continuation_hook.hpp>
#include <boost/asio/handler_invoke_hook.hpp> #include <boost/asio/handler_invoke_hook.hpp>
#include <boost/asio/write.hpp> #include <boost/asio/write.hpp>
#include <boost/throw_exception.hpp>
#include <condition_variable> #include <condition_variable>
#include <mutex> #include <mutex>
#include <ostream> #include <ostream>
@@ -192,7 +193,7 @@ write(SyncWriteStream& stream,
error_code ec; error_code ec;
write(stream, msg, ec); write(stream, msg, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
template<class SyncWriteStream, template<class SyncWriteStream,
@@ -584,7 +585,7 @@ write(SyncWriteStream& stream,
error_code ec; error_code ec;
write(stream, msg, ec); write(stream, msg, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
template<class SyncWriteStream, template<class SyncWriteStream,
@@ -682,7 +683,7 @@ operator<<(std::ostream& os,
error_code ec; error_code ec;
write(oss, msg, ec); write(oss, msg, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
return os; return os;
} }
@@ -702,7 +703,7 @@ operator<<(std::ostream& os,
error_code ec; error_code ec;
write(oss, msg, ec); write(oss, msg, ec);
if(ec && ec != boost::asio::error::eof) if(ec && ec != boost::asio::error::eof)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
return os; return os;
} }

View File

@@ -61,8 +61,8 @@ private:
{ {
if(content_length > if(content_length >
(std::numeric_limits<std::size_t>::max)()) (std::numeric_limits<std::size_t>::max)())
throw std::length_error{ BOOST_THROW_EXCEPTION(std::length_error{
"Content-Length overflow"}; "Content-Length overflow"});
body_.reserve(static_cast< body_.reserve(static_cast<
std::size_t>(content_length)); std::size_t>(content_length));
} }

View File

@@ -21,6 +21,7 @@
#include <boost/asio/handler_continuation_hook.hpp> #include <boost/asio/handler_continuation_hook.hpp>
#include <boost/asio/handler_invoke_hook.hpp> #include <boost/asio/handler_invoke_hook.hpp>
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/throw_exception.hpp>
#include <memory> #include <memory>
#include <type_traits> #include <type_traits>
@@ -316,7 +317,7 @@ accept()
error_code ec; error_code ec;
accept(ec); accept(ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
template<class NextLayer> template<class NextLayer>
@@ -333,7 +334,7 @@ accept_ex(ResponseDecorator const& decorator)
error_code ec; error_code ec;
accept_ex(decorator, ec); accept_ex(decorator, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
template<class NextLayer> template<class NextLayer>
@@ -376,7 +377,7 @@ accept(ConstBufferSequence const& buffers)
error_code ec; error_code ec;
accept(buffers, ec); accept(buffers, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
template<class NextLayer> template<class NextLayer>
@@ -398,7 +399,7 @@ accept_ex(ConstBufferSequence const& buffers,
error_code ec; error_code ec;
accept_ex(buffers, decorator, ec); accept_ex(buffers, decorator, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
template<class NextLayer> template<class NextLayer>
@@ -457,7 +458,7 @@ accept(http::header<true, Fields> const& req)
error_code ec; error_code ec;
accept(req, ec); accept(req, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
template<class NextLayer> template<class NextLayer>
@@ -475,7 +476,7 @@ accept_ex(http::header<true, Fields> const& req,
error_code ec; error_code ec;
accept_ex(req, decorator, ec); accept_ex(req, decorator, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
template<class NextLayer> template<class NextLayer>
@@ -522,7 +523,7 @@ accept(http::header<true, Fields> const& req,
error_code ec; error_code ec;
accept(req, buffers, ec); accept(req, buffers, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
template<class NextLayer> template<class NextLayer>
@@ -545,7 +546,7 @@ accept_ex(http::header<true, Fields> const& req,
error_code ec; error_code ec;
accept_ex(req, buffers, decorator, ec); accept_ex(req, buffers, decorator, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
template<class NextLayer> template<class NextLayer>

View File

@@ -14,6 +14,7 @@
#include <boost/asio/handler_alloc_hook.hpp> #include <boost/asio/handler_alloc_hook.hpp>
#include <boost/asio/handler_continuation_hook.hpp> #include <boost/asio/handler_continuation_hook.hpp>
#include <boost/asio/handler_invoke_hook.hpp> #include <boost/asio/handler_invoke_hook.hpp>
#include <boost/throw_exception.hpp>
#include <memory> #include <memory>
namespace beast { namespace beast {
@@ -227,7 +228,7 @@ close(close_reason const& cr)
error_code ec; error_code ec;
close(cr, ec); close(cr, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
template<class NextLayer> template<class NextLayer>

View File

@@ -18,6 +18,7 @@
#include <boost/asio/handler_continuation_hook.hpp> #include <boost/asio/handler_continuation_hook.hpp>
#include <boost/asio/handler_invoke_hook.hpp> #include <boost/asio/handler_invoke_hook.hpp>
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/throw_exception.hpp>
#include <memory> #include <memory>
namespace beast { namespace beast {
@@ -265,7 +266,7 @@ handshake(string_view const& host,
handshake( handshake(
host, target, ec); host, target, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
template<class NextLayer> template<class NextLayer>
@@ -280,7 +281,7 @@ handshake(response_type& res,
error_code ec; error_code ec;
handshake(res, host, target, ec); handshake(res, host, target, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
template<class NextLayer> template<class NextLayer>
@@ -299,7 +300,7 @@ handshake_ex(string_view const& host,
error_code ec; error_code ec;
handshake_ex(host, target, decorator, ec); handshake_ex(host, target, decorator, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
template<class NextLayer> template<class NextLayer>
@@ -319,7 +320,7 @@ handshake_ex(response_type& res,
error_code ec; error_code ec;
handshake_ex(res, host, target, decorator, ec); handshake_ex(res, host, target, decorator, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
template<class NextLayer> template<class NextLayer>

View File

@@ -15,6 +15,7 @@
#include <boost/asio/handler_alloc_hook.hpp> #include <boost/asio/handler_alloc_hook.hpp>
#include <boost/asio/handler_continuation_hook.hpp> #include <boost/asio/handler_continuation_hook.hpp>
#include <boost/asio/handler_invoke_hook.hpp> #include <boost/asio/handler_invoke_hook.hpp>
#include <boost/throw_exception.hpp>
#include <memory> #include <memory>
namespace beast { namespace beast {
@@ -240,7 +241,7 @@ ping(ping_data const& payload)
error_code ec; error_code ec;
ping(payload, ec); ping(payload, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
template<class NextLayer> template<class NextLayer>
@@ -262,7 +263,7 @@ pong(ping_data const& payload)
error_code ec; error_code ec;
pong(payload, ec); pong(payload, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
template<class NextLayer> template<class NextLayer>

View File

@@ -19,6 +19,7 @@
#include <boost/asio/handler_invoke_hook.hpp> #include <boost/asio/handler_invoke_hook.hpp>
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <boost/throw_exception.hpp>
#include <limits> #include <limits>
#include <memory> #include <memory>
@@ -721,7 +722,7 @@ read_frame(frame_info& fi, DynamicBuffer& buffer)
error_code ec; error_code ec;
read_frame(fi, buffer, ec); read_frame(fi, buffer, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
template<class NextLayer> template<class NextLayer>
@@ -1136,7 +1137,7 @@ read(opcode& op, DynamicBuffer& buffer)
error_code ec; error_code ec;
read(op, buffer, ec); read(op, buffer, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
template<class NextLayer> template<class NextLayer>

View File

@@ -23,6 +23,7 @@
#include <beast/core/detail/type_traits.hpp> #include <beast/core/detail/type_traits.hpp>
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/endian/buffers.hpp> #include <boost/endian/buffers.hpp>
#include <boost/throw_exception.hpp>
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <stdexcept> #include <stdexcept>
@@ -48,20 +49,20 @@ set_option(permessage_deflate const& o)
{ {
if( o.server_max_window_bits > 15 || if( o.server_max_window_bits > 15 ||
o.server_max_window_bits < 9) o.server_max_window_bits < 9)
throw std::invalid_argument{ BOOST_THROW_EXCEPTION(std::invalid_argument{
"invalid server_max_window_bits"}; "invalid server_max_window_bits"});
if( o.client_max_window_bits > 15 || if( o.client_max_window_bits > 15 ||
o.client_max_window_bits < 9) o.client_max_window_bits < 9)
throw std::invalid_argument{ BOOST_THROW_EXCEPTION(std::invalid_argument{
"invalid client_max_window_bits"}; "invalid client_max_window_bits"});
if( o.compLevel < 0 || if( o.compLevel < 0 ||
o.compLevel > 9) o.compLevel > 9)
throw std::invalid_argument{ BOOST_THROW_EXCEPTION(std::invalid_argument{
"invalid compLevel"}; "invalid compLevel"});
if( o.memLevel < 1 || if( o.memLevel < 1 ||
o.memLevel > 9) o.memLevel > 9)
throw std::invalid_argument{ BOOST_THROW_EXCEPTION(std::invalid_argument{
"invalid memLevel"}; "invalid memLevel"});
pmd_opts_ = o; pmd_opts_ = o;
} }

View File

@@ -21,6 +21,7 @@
#include <boost/asio/handler_continuation_hook.hpp> #include <boost/asio/handler_continuation_hook.hpp>
#include <boost/asio/handler_invoke_hook.hpp> #include <boost/asio/handler_invoke_hook.hpp>
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/throw_exception.hpp>
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
@@ -580,7 +581,7 @@ write_frame(bool fin, ConstBufferSequence const& buffers)
error_code ec; error_code ec;
write_frame(fin, buffers, ec); write_frame(fin, buffers, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
template<class NextLayer> template<class NextLayer>
@@ -932,7 +933,7 @@ write(ConstBufferSequence const& buffers)
error_code ec; error_code ec;
write(buffers, ec); write(buffers, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
template<class NextLayer> template<class NextLayer>

View File

@@ -11,6 +11,7 @@
#include <beast/config.hpp> #include <beast/config.hpp>
#include <beast/websocket/rfc6455.hpp> #include <beast/websocket/rfc6455.hpp>
#include <beast/core/detail/type_traits.hpp> #include <beast/core/detail/type_traits.hpp>
#include <boost/throw_exception.hpp>
#include <algorithm> #include <algorithm>
#include <cstdint> #include <cstdint>
#include <functional> #include <functional>
@@ -90,8 +91,8 @@ struct message_type
message_type(opcode op) message_type(opcode op)
{ {
if(op != opcode::binary && op != opcode::text) if(op != opcode::binary && op != opcode::text)
throw beast::detail::make_exception<std::invalid_argument>( BOOST_THROW_EXCEPTION(std::invalid_argument{
"bad opcode", __FILE__, __LINE__); "bad opcode"});
value = op; value = op;
} }
}; };
@@ -234,8 +235,8 @@ struct read_buffer_size
: value(n) : value(n)
{ {
if(n < 8) if(n < 8)
throw beast::detail::make_exception<std::invalid_argument>( BOOST_THROW_EXCEPTION(std::invalid_argument{
"read buffer size is too small", __FILE__, __LINE__); "read buffer size is too small"});
} }
}; };
#endif #endif
@@ -315,8 +316,8 @@ struct write_buffer_size
: value(n) : value(n)
{ {
if(n < 8) if(n < 8)
throw beast::detail::make_exception<std::invalid_argument>( BOOST_THROW_EXCEPTION(std::invalid_argument{
"write buffer size is too small", __FILE__, __LINE__); "write buffer size is too small"});
} }
}; };
#endif #endif

View File

@@ -40,6 +40,7 @@
#include <beast/core/detail/type_traits.hpp> #include <beast/core/detail/type_traits.hpp>
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/optional.hpp> #include <boost/optional.hpp>
#include <boost/throw_exception.hpp>
#include <cstdint> #include <cstdint>
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
@@ -894,19 +895,17 @@ doReset(
if(windowBits == 8) if(windowBits == 8)
windowBits = 9; windowBits = 9;
using beast::detail::make_exception;
if(level < 0 || level > 9) if(level < 0 || level > 9)
throw make_exception<std::invalid_argument>( BOOST_THROW_EXCEPTION(std::invalid_argument{
"invalid level", __FILE__, __LINE__); "invalid level"});
if(windowBits < 8 || windowBits > 15) if(windowBits < 8 || windowBits > 15)
throw make_exception<std::invalid_argument>( BOOST_THROW_EXCEPTION(std::invalid_argument{
"invalid windowBits", __FILE__, __LINE__); "invalid windowBits"});
if(memLevel < 1 || memLevel > MAX_MEM_LEVEL) if(memLevel < 1 || memLevel > MAX_MEM_LEVEL)
throw make_exception<std::invalid_argument>( BOOST_THROW_EXCEPTION(std::invalid_argument{
"invalid memLevel", __FILE__, __LINE__); "invalid memLevel"});
w_bits_ = windowBits; w_bits_ = windowBits;

View File

@@ -41,6 +41,7 @@
#include <beast/zlib/detail/ranges.hpp> #include <beast/zlib/detail/ranges.hpp>
#include <beast/zlib/detail/window.hpp> #include <beast/zlib/detail/window.hpp>
#include <beast/core/detail/type_traits.hpp> #include <beast/core/detail/type_traits.hpp>
#include <boost/throw_exception.hpp>
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <cstdint> #include <cstdint>
@@ -233,8 +234,8 @@ inflate_stream::
doReset(int windowBits) doReset(int windowBits)
{ {
if(windowBits < 8 || windowBits > 15) if(windowBits < 8 || windowBits > 15)
throw beast::detail::make_exception<std::domain_error>( BOOST_THROW_EXCEPTION(std::domain_error{
"windowBits out of range", __FILE__, __LINE__); "windowBits out of range"});
w_.reset(windowBits); w_.reset(windowBits);
bi_.flush(); bi_.flush();
@@ -708,8 +709,8 @@ doWrite(z_params& zs, Flush flush, error_code& ec)
case SYNC: case SYNC:
default: default:
throw beast::detail::make_exception<std::logic_error>( BOOST_THROW_EXCEPTION(std::logic_error{
"stream error", __FILE__, __LINE__); "stream error"});
} }
} }
} }
@@ -935,8 +936,8 @@ inflate_table(
auto const not_enough = [] auto const not_enough = []
{ {
throw beast::detail::make_exception<std::logic_error>( BOOST_THROW_EXCEPTION(std::logic_error{
"insufficient output size when inflating tables", __FILE__, __LINE__); "insufficient output size when inflating tables"});
}; };
// check available table space // check available table space
@@ -1077,7 +1078,7 @@ get_fixed_tables() ->
inflate_table(build::lens, inflate_table(build::lens,
lens, 288, &next, &lenbits, work, ec); lens, 288, &next, &lenbits, work, ec);
if(ec) if(ec)
throw std::logic_error{ec.message()}; BOOST_THROW_EXCEPTION(std::logic_error{ec.message()});
} }
// VFALCO These fixups are from ZLib // VFALCO These fixups are from ZLib
@@ -1093,7 +1094,7 @@ get_fixed_tables() ->
inflate_table(build::dists, inflate_table(build::dists,
lens, 32, &next, &distbits, work, ec); lens, 32, &next, &distbits, work, ec);
if(ec) if(ec)
throw std::logic_error{ec.message()}; BOOST_THROW_EXCEPTION(std::logic_error{ec.message()});
} }
} }
}; };

View File

@@ -16,6 +16,7 @@
#include <beast/core/type_traits.hpp> #include <beast/core/type_traits.hpp>
#include <boost/asio/buffer.hpp> #include <boost/asio/buffer.hpp>
#include <boost/system/error_code.hpp> #include <boost/system/error_code.hpp>
#include <boost/throw_exception.hpp>
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <type_traits> #include <type_traits>
@@ -174,7 +175,7 @@ public:
error_code ec; error_code ec;
auto const used = write(data, size, ec); auto const used = write(data, size, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
return used; return used;
} }
@@ -189,7 +190,7 @@ public:
error_code ec; error_code ec;
auto const used = write(buffers, ec); auto const used = write(buffers, ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
return used; return used;
} }
@@ -204,7 +205,7 @@ public:
error_code ec; error_code ec;
write_eof(ec); write_eof(ec);
if(ec) if(ec)
throw system_error{ec}; BOOST_THROW_EXCEPTION(system_error{ec});
} }
void void