diff --git a/include/ircd/exception.h b/include/ircd/exception.h index 8169f96fe..22a6b6b81 100644 --- a/include/ircd/exception.h +++ b/include/ircd/exception.h @@ -41,6 +41,10 @@ namespace ircd [[noreturn]] void assertion(std::exception_ptr) noexcept(RB_DEBUG); [[noreturn]] void assertion() noexcept(RB_DEBUG); + // util + std::exception_ptr make_system_error(const int &code = errno); + [[noreturn]] void throw_system_error(const int &code = errno); + // Can be used to clobber the std::terminate_handler void aborting() noexcept; } diff --git a/ircd/exception.cc b/ircd/exception.cc index 3b33f98ff..bd67c0040 100644 --- a/ircd/exception.cc +++ b/ircd/exception.cc @@ -23,6 +23,32 @@ * */ +[[noreturn]] static void +ircd_terminate_handler() +noexcept +{ + std::abort(); +} + +void +ircd::aborting() +noexcept +{ + std::set_terminate(&ircd_terminate_handler); +} + +void +ircd::throw_system_error(const int &code) +{ + throw std::system_error(code, std::system_category()); +} + +std::exception_ptr +ircd::make_system_error(const int &code) +{ + return std::make_exception_ptr(std::system_error(code, std::system_category())); +} + ssize_t ircd::exception::generate(const char *const &fmt, const va_rtti &ap) @@ -116,17 +142,3 @@ noexcept log::critical("IRCd Terminated: %s", e.what()); throw e; } - -[[noreturn]] static void -ircd_terminate_handler() -noexcept -{ - std::abort(); -} - -void -ircd::aborting() -noexcept -{ - std::set_terminate(&ircd_terminate_handler); -}