From ca113516920015cccdea95d9b288adfa35a947ab Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 15 Oct 2018 22:29:39 -0700 Subject: [PATCH] ircd: Add assertion() overload taking message string. --- include/ircd/exception.h | 1 + ircd/exception.cc | 27 +++++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/include/ircd/exception.h b/include/ircd/exception.h index 7cb0c5f26..89943cb62 100644 --- a/include/ircd/exception.h +++ b/include/ircd/exception.h @@ -32,6 +32,7 @@ namespace ircd // Terminates in debug mode; throws in release mode; always logs critical. [[noreturn]] void assertion(const std::exception &) noexcept(RB_DEBUG_LEVEL); [[noreturn]] void assertion(std::exception_ptr) noexcept(RB_DEBUG_LEVEL); + [[noreturn]] void assertion(const string_view &) noexcept(RB_DEBUG_LEVEL); [[noreturn]] void assertion() noexcept(RB_DEBUG_LEVEL); // util diff --git a/ircd/exception.cc b/ircd/exception.cc index a4b27a191..ab265961b 100644 --- a/ircd/exception.cc +++ b/ircd/exception.cc @@ -181,16 +181,31 @@ void ircd::assertion() noexcept(RB_DEBUG_LEVEL) { + static const auto &default_message + { + "without exception"_sv + }; + + assertion(default_message); +} + +void +ircd::assertion(const string_view &msg) +noexcept(RB_DEBUG_LEVEL) +{ + log::critical + { + "IRCd Assertion :%s", msg + }; + if(std::uncaught_exceptions()) assertion(std::current_exception()); - log::critical - { - "IRCd Assertion without exception." - }; - assert(0); - throw assertive{}; + throw assertive + { + "IRCd Assertion :%s", msg + }; } void