From 29db3de6c0a9b654321a0408bb6cc837d023e4f7 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 29 Jan 2017 15:37:42 -0500 Subject: [PATCH] wrap most instances of throw, and terminate on builds where exceptions are disabled (#1639) wrap most instances of throw, and terminate on builds where exceptions are disabled --- include/libtorrent/Makefile.am | 1 + include/libtorrent/aux_/dev_random.hpp | 14 ++--- include/libtorrent/aux_/throw.hpp | 54 +++++++++++++++++++ .../libtorrent/aux_/win_crypto_provider.hpp | 39 ++++---------- include/libtorrent/buffer.hpp | 12 ++--- include/libtorrent/config.hpp | 2 + include/libtorrent/torrent_handle.hpp | 2 +- src/disk_io_thread.cpp | 3 +- src/entry.cpp | 11 ++-- src/ip_notifier.cpp | 9 ++-- src/kademlia/node.cpp | 7 +-- src/magnet_uri.cpp | 3 +- src/random.cpp | 16 ++---- src/session_handle.cpp | 7 +-- src/torrent_handle.cpp | 21 ++------ src/torrent_info.cpp | 31 +++++------ src/utf8.cpp | 13 ++--- 17 files changed, 116 insertions(+), 129 deletions(-) create mode 100644 include/libtorrent/aux_/throw.hpp diff --git a/include/libtorrent/Makefile.am b/include/libtorrent/Makefile.am index d69fb37a2..304df702a 100644 --- a/include/libtorrent/Makefile.am +++ b/include/libtorrent/Makefile.am @@ -196,6 +196,7 @@ nobase_include_HEADERS = \ aux_/numeric_cast.hpp \ aux_/unique_ptr.hpp \ aux_/alloca.hpp \ + aux_/throw.hpp \ aux_/typed_span.hpp \ \ extensions/smart_ban.hpp \ diff --git a/include/libtorrent/aux_/dev_random.hpp b/include/libtorrent/aux_/dev_random.hpp index 39dca4ef2..01216eb34 100644 --- a/include/libtorrent/aux_/dev_random.hpp +++ b/include/libtorrent/aux_/dev_random.hpp @@ -35,6 +35,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" #include "libtorrent/span.hpp" +#include "libtorrent/aux_/throw.hpp" + #include namespace libtorrent { namespace aux { @@ -46,11 +48,7 @@ namespace libtorrent { namespace aux { { if (m_fd < 0) { -#ifndef BOOST_NO_EXCEPTIONS - throw system_error(error_code(errno, system_category())); -#else - std::terminate(); -#endif + throw_ex(error_code(errno, system_category())); } } dev_random(dev_random const&) = delete; @@ -61,11 +59,7 @@ namespace libtorrent { namespace aux { std::int64_t const ret = ::read(m_fd, buffer.data(), buffer.size()); if (ret != int(buffer.size())) { -#ifndef BOOST_NO_EXCEPTIONS - throw system_error(errors::no_entropy); -#else - std::terminate(); -#endif + throw_ex(errors::no_entropy); } } diff --git a/include/libtorrent/aux_/throw.hpp b/include/libtorrent/aux_/throw.hpp new file mode 100644 index 000000000..fe44e5276 --- /dev/null +++ b/include/libtorrent/aux_/throw.hpp @@ -0,0 +1,54 @@ +/* + +Copyright (c) 2017, Arvid Norberg +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the distribution. + * Neither the name of the author nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. + +*/ + +#ifndef TORRENT_THROW_HPP_INCLUDED +#define TORRENT_THROW_HPP_INCLUDED + +#include // for forward() + +#include "libtorrent/config.hpp" + +namespace libtorrent { namespace aux +{ + template + void TORRENT_NO_RETURN throw_ex(Args&&... args) + { +#ifdef BOOST_NO_EXCEPTIONS + std::terminate(); +#else + throw T(std::forward(args)...); +#endif + } +}} + +#endif + diff --git a/include/libtorrent/aux_/win_crypto_provider.hpp b/include/libtorrent/aux_/win_crypto_provider.hpp index 015bc9f82..fdbc0164c 100644 --- a/include/libtorrent/aux_/win_crypto_provider.hpp +++ b/include/libtorrent/aux_/win_crypto_provider.hpp @@ -35,9 +35,12 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/config.hpp" #include "libtorrent/error_code.hpp" +#include "libtorrent/aux_/throw.hpp" +#include "libtorrent/aux_/disable_warnings_push.hpp" #include #include +#include "libtorrent/aux_/disable_warnings_pop.hpp" namespace libtorrent { namespace aux { @@ -48,11 +51,7 @@ namespace libtorrent { namespace aux if (CryptAcquireContext(&ret, nullptr, nullptr, provider_type , CRYPT_VERIFYCONTEXT) == false) { -#ifndef BOOST_NO_EXCEPTIONS - throw system_error(error_code(GetLastError(), system_category())); -#else - std::terminate(); -#endif + throw_ex(error_code(GetLastError(), system_category())); } return ret; } @@ -63,11 +62,7 @@ namespace libtorrent { namespace aux if (!CryptGenRandom(provider, int(buffer.size()) , reinterpret_cast(buffer.data()))) { -#ifndef BOOST_NO_EXCEPTIONS - throw system_error(error_code(GetLastError(), system_category())); -#else - std::terminate(); -#endif + throw_ex(error_code(GetLastError(), system_category())); } } @@ -98,11 +93,7 @@ namespace libtorrent { namespace aux { if (CryptHashData(m_hash, reinterpret_cast(data.data()), int(data.size()), 0) == false) { -#ifndef BOOST_NO_EXCEPTIONS - throw system_error(error_code(GetLastError(), system_category())); -#else - std::terminate(); -#endif + throw_ex(error_code(GetLastError(), system_category())); } } @@ -112,11 +103,7 @@ namespace libtorrent { namespace aux if (CryptGetHashParam(m_hash, HP_HASHVAL , reinterpret_cast(digest), &size, 0) == false) { -#ifndef BOOST_NO_EXCEPTIONS - throw system_error(error_code(GetLastError(), system_category())); -#else - std::terminate(); -#endif + throw_ex(error_code(GetLastError(), system_category())); } TORRENT_ASSERT(size == DWORD(digest_size)); } @@ -126,11 +113,7 @@ namespace libtorrent { namespace aux HCRYPTHASH ret; if (CryptCreateHash(get_provider(), AlgId, 0, 0, &ret) == false) { -#ifndef BOOST_NO_EXCEPTIONS - throw system_error(error_code(GetLastError(), system_category())); -#else - std::terminate(); -#endif + throw_ex(error_code(GetLastError(), system_category())); } return ret; } @@ -140,11 +123,7 @@ namespace libtorrent { namespace aux HCRYPTHASH ret; if (CryptDuplicateHash(h.m_hash, 0, 0, &ret) == false) { -#ifndef BOOST_NO_EXCEPTIONS - throw system_error(error_code(GetLastError(), system_category())); -#else - std::terminate(); -#endif + throw_ex(error_code(GetLastError(), system_category())); } return ret; } diff --git a/include/libtorrent/buffer.hpp b/include/libtorrent/buffer.hpp index 8e26895d6..71da7fe2f 100644 --- a/include/libtorrent/buffer.hpp +++ b/include/libtorrent/buffer.hpp @@ -41,6 +41,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/invariant_check.hpp" #include "libtorrent/assert.hpp" #include "libtorrent/span.hpp" +#include "libtorrent/aux_/throw.hpp" #if defined __GLIBC__ #include @@ -73,15 +74,10 @@ public: // for a variation of "malloc_size()" size = (size + 7) & (~std::size_t(0x7)); + // we have to use malloc here, to be compatible with the fancy query + // functions below m_begin = static_cast(std::malloc(size)); - if (m_begin == nullptr) - { -#ifndef BOOST_NO_EXCEPTIONS - throw std::bad_alloc(); -#else - std::terminate(); -#endif - } + if (m_begin == nullptr) aux::throw_ex(); // the actual allocation may be larger than we requested. If so, let the // user take advantage of every single byte diff --git a/include/libtorrent/config.hpp b/include/libtorrent/config.hpp index 5283f8208..d3e51946f 100644 --- a/include/libtorrent/config.hpp +++ b/include/libtorrent/config.hpp @@ -326,6 +326,8 @@ POSSIBILITY OF SUCH DAMAGE. // that could be marked noreturn. #if defined __clang__ || defined __GNUC__ #define TORRENT_NO_RETURN __attribute((noreturn)) +#elif _MSC_VER +#define TORRENT_NO_RETURN __declspec(noreturn) #else #define TORRENT_NO_RETURN #endif diff --git a/include/libtorrent/torrent_handle.hpp b/include/libtorrent/torrent_handle.hpp index 25ff063ba..237441f17 100644 --- a/include/libtorrent/torrent_handle.hpp +++ b/include/libtorrent/torrent_handle.hpp @@ -74,7 +74,7 @@ namespace libtorrent class torrent; #ifndef BOOST_NO_EXCEPTIONS - void throw_invalid_handle() TORRENT_NO_RETURN; + void TORRENT_NO_RETURN throw_invalid_handle(); #endif using std::shared_ptr; diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index acf50ef18..0984bf60d 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -36,6 +36,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/string_util.hpp" // for allocate_string_copy #include "libtorrent/disk_buffer_holder.hpp" #include "libtorrent/aux_/alloca.hpp" +#include "libtorrent/aux_/throw.hpp" #include "libtorrent/error_code.hpp" #include "libtorrent/error.hpp" #include "libtorrent/file_pool.hpp" @@ -1663,7 +1664,7 @@ namespace libtorrent bool exceeded = false; disk_buffer_holder buffer(*this, m_disk_cache.allocate_buffer(exceeded, o, "receive buffer")); - if (!buffer) throw std::bad_alloc(); + if (!buffer) aux::throw_ex(); std::memcpy(buffer.get(), buf, r.length); disk_io_job* j = allocate_job(disk_io_job::write); diff --git a/src/entry.cpp b/src/entry.cpp index f18e3903f..5f9a72e70 100644 --- a/src/entry.cpp +++ b/src/entry.cpp @@ -43,6 +43,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/entry.hpp" #include "libtorrent/hex.hpp" #include "libtorrent/string_util.hpp" +#include "libtorrent/aux_/throw.hpp" namespace libtorrent { @@ -71,14 +72,8 @@ namespace libtorrent namespace { - TORRENT_NO_RETURN inline void throw_error() - { -#ifndef BOOST_NO_EXCEPTIONS - throw system_error(errors::invalid_entry_type); -#else - std::terminate(); -#endif - } + inline void TORRENT_NO_RETURN throw_error() + { aux::throw_ex(errors::invalid_entry_type); } template void call_destructor(T* o) diff --git a/src/ip_notifier.cpp b/src/ip_notifier.cpp index 3844b51c0..8594b929f 100644 --- a/src/ip_notifier.cpp +++ b/src/ip_notifier.cpp @@ -38,6 +38,8 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/disable_warnings_pop.hpp" #endif +#include "libtorrent/aux_/throw.hpp" + using namespace std::placeholders; namespace libtorrent @@ -54,12 +56,7 @@ namespace libtorrent #if defined TORRENT_BUILD_SIMULATOR TORRENT_UNUSED(ios); #elif defined TORRENT_WINDOWS - if (!m_hnd.is_open()) -#ifndef BOOST_NO_EXCEPTIONS - throw system_error(WSAGetLastError(), system_category()); -#else - std::terminate(); -#endif // BOOST_NO_EXCEPTIONS + if (!m_hnd.is_open()) aux::throw_ex(WSAGetLastError(), system_category()); m_ovl.hEvent = m_hnd.native_handle(); #elif !TORRENT_USE_NETLINK TORRENT_UNUSED(ios); diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index 3ca44af13..804818b9a 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -49,6 +49,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/random.hpp" #include #include +#include "libtorrent/aux_/throw.hpp" #include "libtorrent/alert_types.hpp" // for dht_lookup #include "libtorrent/performance_counters.hpp" // for counters @@ -1187,11 +1188,7 @@ node::protocol_descriptor const& node::map_protocol_to_descriptor(udp protocol) } TORRENT_ASSERT_FAIL(); -#ifndef BOOST_NO_EXCEPTIONS - throw std::out_of_range("unknown protocol"); -#else - std::terminate(); -#endif + aux::throw_ex("unknown protocol"); } } } // namespace libtorrent::dht diff --git a/src/magnet_uri.cpp b/src/magnet_uri.cpp index d2c1013c5..16b06859c 100644 --- a/src/magnet_uri.cpp +++ b/src/magnet_uri.cpp @@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/magnet_uri.hpp" #include "libtorrent/session.hpp" #include "libtorrent/aux_/escape_string.hpp" +#include "libtorrent/aux_/throw.hpp" #include "libtorrent/torrent_status.hpp" #include "libtorrent/torrent_info.hpp" #include "libtorrent/announce_entry.hpp" @@ -160,7 +161,7 @@ namespace libtorrent { error_code ec; torrent_handle ret = add_magnet_uri_deprecated(ses, uri, p, ec); - if (ec) throw system_error(ec); + if (ec) aux::throw_ex(ec); return ret; } #endif // BOOST_NO_EXCEPTIONS diff --git a/src/random.cpp b/src/random.cpp index 6d918874a..0f242d516 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -34,23 +34,22 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/random.hpp" #include "libtorrent/error_code.hpp" #include "libtorrent/aux_/openssl.hpp" - -#include "libtorrent/aux_/disable_warnings_push.hpp" +#include "libtorrent/aux_/throw.hpp" #if TORRENT_USE_CRYPTOAPI #include "libtorrent/aux_/win_crypto_provider.hpp" #elif defined TORRENT_USE_LIBCRYPTO +#include "libtorrent/aux_/disable_warnings_push.hpp" extern "C" { #include #include } +#include "libtorrent/aux_/disable_warnings_pop.hpp" #endif -#include "libtorrent/aux_/disable_warnings_pop.hpp" - #if TORRENT_USE_DEV_RANDOM #include "libtorrent/aux_/dev_random.hpp" #endif @@ -94,14 +93,7 @@ namespace libtorrent int r = RAND_bytes(reinterpret_cast(buffer.data()) , int(buffer.size())); - if (r != 1) - { -#ifndef BOOST_NO_EXCEPTIONS - throw system_error(errors::no_entropy); -#else - std::terminate(); -#endif - } + if (r != 1) aux::throw_ex(errors::no_entropy); #else // fallback diff --git a/src/session_handle.cpp b/src/session_handle.cpp index f3b8e4ba6..291cb64b7 100644 --- a/src/session_handle.cpp +++ b/src/session_handle.cpp @@ -33,6 +33,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/session_handle.hpp" #include "libtorrent/aux_/session_impl.hpp" #include "libtorrent/aux_/session_call.hpp" +#include "libtorrent/aux_/throw.hpp" #include "libtorrent/torrent.hpp" #include "libtorrent/lazy_entry.hpp" #include "libtorrent/peer_class.hpp" @@ -321,7 +322,7 @@ namespace libtorrent error_code ec; auto ecr = std::ref(ec); torrent_handle r = sync_call_ret(&session_impl::add_torrent, p, ecr); - if (ec) throw system_error(ec); + if (ec) aux::throw_ex(ec); return r; } #endif @@ -677,7 +678,7 @@ namespace libtorrent TORRENT_ASSERT(ret == 0); #ifndef BOOST_NO_EXCEPTIONS - if (ret != 0) throw system_error(ec); + if (ret != 0) aux::throw_ex(ec); #endif sync_call(&session_impl::load_state, &e, flags); } @@ -704,7 +705,7 @@ namespace libtorrent TORRENT_ASSERT(ret == 0); #ifndef BOOST_NO_EXCEPTIONS - if (ret != 0) throw system_error(ec); + if (ret != 0) aux::throw_ex(ec); #endif sync_call(&session_impl::load_state, &e, flags); } diff --git a/src/torrent_handle.cpp b/src/torrent_handle.cpp index 6962c7dcc..90475ccbf 100644 --- a/src/torrent_handle.cpp +++ b/src/torrent_handle.cpp @@ -43,6 +43,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/entry.hpp" #include "libtorrent/aux_/session_impl.hpp" #include "libtorrent/aux_/session_call.hpp" +#include "libtorrent/aux_/throw.hpp" #include "libtorrent/invariant_check.hpp" #include "libtorrent/utf8.hpp" #include "libtorrent/announce_entry.hpp" @@ -57,7 +58,7 @@ namespace libtorrent { #ifndef BOOST_NO_EXCEPTIONS - void throw_invalid_handle() + void TORRENT_NO_RETURN throw_invalid_handle() { throw system_error(errors::invalid_torrent_handle); } @@ -67,14 +68,7 @@ namespace libtorrent void torrent_handle::async_call(Fun f, Args&&... a) const { std::shared_ptr t = m_torrent.lock(); - if (!t) - { -#ifndef BOOST_NO_EXCEPTIONS - throw_invalid_handle(); -#else - std::terminate(); -#endif - } + if (!t) aux::throw_ex(errors::invalid_torrent_handle); session_impl& ses = static_cast(t->session()); ses.get_io_service().dispatch([=,&ses] () { @@ -101,14 +95,7 @@ namespace libtorrent void torrent_handle::sync_call(Fun f, Args&&... a) const { std::shared_ptr t = m_torrent.lock(); - if (!t) - { -#ifndef BOOST_NO_EXCEPTIONS - throw_invalid_handle(); -#else - std::terminate(); -#endif - } + if (!t) aux::throw_ex(errors::invalid_torrent_handle); session_impl& ses = static_cast(t->session()); // this is the flag to indicate the call has completed diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index e0e89e5dc..670f87417 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -46,6 +46,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/aux_/escape_string.hpp" // maybe_url_encode #include "libtorrent/aux_/merkle.hpp" // for merkle_* #include "libtorrent/aux_/time.hpp" +#include "libtorrent/aux_/throw.hpp" #include "libtorrent/add_torrent_params.hpp" #include "libtorrent/magnet_uri.hpp" #include "libtorrent/announce_entry.hpp" @@ -801,15 +802,11 @@ namespace libtorrent error_code ec; if (bdecode(buf.first, buf.first + buf.second, e, ec) != 0) { -#ifndef BOOST_NO_EXCEPTIONS - throw system_error(ec); -#else - return; -#endif + aux::throw_ex(ec); } #ifndef BOOST_NO_EXCEPTIONS if (!parse_torrent_file(e, ec, 0)) - throw system_error(ec); + aux::throw_ex(ec); #else parse_torrent_file(e, ec, 0); #endif @@ -827,14 +824,14 @@ namespace libtorrent if (tmp.empty() || bdecode(&tmp[0], &tmp[0] + tmp.size(), e, ec) != 0) { #ifndef BOOST_NO_EXCEPTIONS - throw system_error(ec); + aux::throw_ex(ec); #else return; #endif } #ifndef BOOST_NO_EXCEPTIONS if (!parse_torrent_file(e, ec, 0)) - throw system_error(ec); + aux::throw_ex(ec); #else parse_torrent_file(e, ec, 0); #endif @@ -848,7 +845,7 @@ namespace libtorrent { error_code ec; if (!parse_torrent_file(torrent_file, ec, flags)) - throw system_error(ec); + aux::throw_ex(ec); INVARIANT_CHECK; } @@ -860,10 +857,10 @@ namespace libtorrent error_code ec; bdecode_node e; if (bdecode(buffer, buffer + size, e, ec) != 0) - throw system_error(ec); + aux::throw_ex(ec); if (!parse_torrent_file(e, ec, flags)) - throw system_error(ec); + aux::throw_ex(ec); INVARIANT_CHECK; } @@ -874,14 +871,14 @@ namespace libtorrent std::vector buf; error_code ec; int ret = load_file(filename, buf, ec); - if (ret < 0) throw system_error(ec); + if (ret < 0) aux::throw_ex(ec); bdecode_node e; if (buf.empty() || bdecode(&buf[0], &buf[0] + buf.size(), e, ec) != 0) - throw system_error(ec); + aux::throw_ex(ec); if (!parse_torrent_file(e, ec, flags)) - throw system_error(ec); + aux::throw_ex(ec); INVARIANT_CHECK; } @@ -894,14 +891,14 @@ namespace libtorrent std::vector buf; error_code ec; int ret = load_file(wchar_utf8(filename), buf, ec); - if (ret < 0) throw system_error(ec); + if (ret < 0) aux::throw_ex(ec); bdecode_node e; if (buf.empty() || bdecode(&buf[0], &buf[0] + buf.size(), e, ec) != 0) - throw system_error(ec); + aux::throw_ex(ec); if (!parse_torrent_file(e, ec, flags)) - throw system_error(ec); + aux::throw_ex(ec); INVARIANT_CHECK; } diff --git a/src/utf8.cpp b/src/utf8.cpp index da119036a..7cb77175c 100644 --- a/src/utf8.cpp +++ b/src/utf8.cpp @@ -41,6 +41,7 @@ POSSIBILITY OF SUCH DAMAGE. #include "libtorrent/assert.hpp" #include "libtorrent/error_code.hpp" #include "libtorrent/ConvertUTF.h" +#include "libtorrent/aux_/throw.hpp" #ifdef __clang__ @@ -240,11 +241,7 @@ namespace libtorrent { error_code ec; std::wstring ret = utf8_wchar(wide, ec); -#ifndef BOOST_NO_EXCEPTIONS - if (ec) throw system_error(ec); -#else - if (ec) std::terminate(); -#endif + if (ec) aux::throw_ex(ec); return ret; } @@ -267,11 +264,7 @@ namespace libtorrent { error_code ec; std::string ret = wchar_utf8(wide, ec); -#ifndef BOOST_NO_EXCEPTIONS - if (ec) throw system_error(ec); -#else - if (ec) std::terminate(); -#endif + if (ec) aux::throw_ex(ec); return ret; } }