From 402acc151aeab3a1416cd61a5fe1de083b39b768 Mon Sep 17 00:00:00 2001 From: Ed Tanous Date: Mon, 10 Jul 2023 16:45:45 -0700 Subject: [PATCH] Use boost::throw_exception Using boost::throw_exception allows for modifications to these exceptions on a per-application basis, including overriding with custom implementations. This also has the benefit of allowing compilation with -fno-exceptions set, which should make this code more portable. --- include/boost/process/detail/config.hpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/include/boost/process/detail/config.hpp b/include/boost/process/detail/config.hpp index 646daa096..eec7bde10 100644 --- a/include/boost/process/detail/config.hpp +++ b/include/boost/process/detail/config.hpp @@ -21,7 +21,9 @@ #include #include +#include #include +#include #if defined(BOOST_POSIX_API) #include @@ -71,31 +73,33 @@ inline std::error_code get_last_error() noexcept } #endif -inline void throw_last_error(const std::string & msg) +inline void throw_last_error(const std::string & msg, boost::source_location const & loc = boost::source_location()) { - throw process_error(get_last_error(), msg); + boost::throw_exception(process_error(get_last_error(), msg), loc); } -inline void throw_last_error(const char * msg) +inline void throw_last_error(const char * msg, boost::source_location const & loc = boost::source_location()) { - throw process_error(get_last_error(), msg); + boost::throw_exception(process_error(get_last_error(), msg), loc); } -inline void throw_last_error() +inline void throw_last_error(boost::source_location const & loc = boost::source_location()) { - throw process_error(get_last_error()); + boost::throw_exception(process_error(get_last_error()), loc); } -inline void throw_error(const std::error_code& ec) +inline void throw_error(const std::error_code& ec, + boost::source_location const & loc = boost::source_location()) { if (ec) - throw process_error(ec); + boost::throw_exception(process_error(ec), loc); } -inline void throw_error(const std::error_code& ec, const char* msg) +inline void throw_error(const std::error_code& ec, const char* msg, + boost::source_location const & loc = boost::source_location()) { if (ec) - throw process_error(ec, msg); + boost::throw_exception(process_error(ec, msg), loc); } template constexpr Char null_char();