From 139059f3819993f4072507306bcd75390124499c Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 26 Feb 2020 11:57:54 -0800 Subject: [PATCH] ircd: Split panic/terminate exception related into header. --- include/ircd/exception.h | 51 ----------------------------- include/ircd/ircd.h | 1 + include/ircd/panic.h | 70 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 51 deletions(-) create mode 100644 include/ircd/panic.h diff --git a/include/ircd/exception.h b/include/ircd/exception.h index 74075dd98..8674dbe10 100644 --- a/include/ircd/exception.h +++ b/include/ircd/exception.h @@ -22,7 +22,6 @@ namespace boost::system namespace ircd { - struct terminate; struct exception; // Root exception // util @@ -53,10 +52,6 @@ namespace ircd std::string string(const std::system_error &); std::string string(const boost::system::error_code &); std::string string(const boost::system::system_error &); - - void panicking(const std::exception &) noexcept; - void panicking(const std::exception_ptr &) noexcept; - void _aborting_() noexcept; } /// The root exception type. @@ -112,15 +107,6 @@ struct ircd::exception exception &operator=(const exception &) = delete; }; -/// Always prefer ircd::terminate() to std::terminate() for all project code. -struct ircd::terminate -{ - [[noreturn]] terminate(const std::exception &) noexcept; - [[noreturn]] terminate(std::exception_ptr) noexcept; - [[noreturn]] terminate(const string_view &) noexcept; - [[noreturn]] terminate() noexcept; -}; - /// Exception generator convenience macro /// /// If you want to create your own exception type, you have found the right @@ -215,39 +201,6 @@ struct name \ } \ }; -/// Creates a panic-type exception. -/// -/// Throwable which will terminate on construction in debug mode but throw -/// normally in release mode. Ideally this should never be thrown in release -/// mode because the termination in debug means a test can never pass and -/// the triggering callsite should be eliminated. Nevertheless it throws -/// normally in release mode for recovering at an exception handler. -#define IRCD_PANICKING(parent, name) \ -struct name \ -:parent \ -{ \ - template \ - name(const string_view &fmt, args&&... ap) noexcept \ - :parent{generate_skip} \ - { \ - generate(#name, fmt, ircd::va_rtti{std::forward(ap)...}); \ - ircd::panicking(*this); \ - } \ - \ - template \ - name(const string_view &fmt = " ") noexcept \ - :parent{generate_skip} \ - { \ - generate(#name, fmt, ircd::va_rtti{}); \ - ircd::panicking(*this); \ - } \ - \ - name(generate_skip_t) \ - :parent{generate_skip} \ - { \ - } \ -}; - namespace ircd { /// Root error exception type. Inherit from this. @@ -258,10 +211,6 @@ namespace ircd /// IRCD_EXCEPTION(exception, error) // throw ircd::error("something bad") IRCD_EXCEPTION(error, user_error) // throw ircd::user_error("something silly") - - // panic errors; see IRCD_PANICKING docs. - IRCD_PANICKING(exception, panic) - IRCD_PANICKING(panic, not_implemented) } template +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice is present in all copies. The +// full license for this software is available in the LICENSE file. + +#pragma once +#define HAVE_IRCD_PANIC_H + +namespace ircd +{ + struct terminate; + + void panicking(const std::exception &) noexcept; + void panicking(const std::exception_ptr &) noexcept; + void _aborting_() noexcept; +} + +/// Always prefer ircd::terminate() to std::terminate() for all project code. +struct ircd::terminate +{ + [[noreturn]] terminate(const std::exception &) noexcept; + [[noreturn]] terminate(std::exception_ptr) noexcept; + [[noreturn]] terminate(const string_view &) noexcept; + [[noreturn]] terminate() noexcept; +}; + +/// Creates a panic-type exception. +/// +/// Throwable which will terminate on construction in debug mode but throw +/// normally in release mode. Ideally this should never be thrown in release +/// mode because the termination in debug means a test can never pass and +/// the triggering callsite should be eliminated. Nevertheless it throws +/// normally in release mode for recovering at an exception handler. +#define IRCD_PANICKING(parent, name) \ +struct name \ +:parent \ +{ \ + template \ + name(const string_view &fmt, args&&... ap) noexcept \ + :parent{generate_skip} \ + { \ + generate(#name, fmt, ircd::va_rtti{std::forward(ap)...}); \ + ircd::panicking(*this); \ + } \ + \ + template \ + name(const string_view &fmt = " ") noexcept \ + :parent{generate_skip} \ + { \ + generate(#name, fmt, ircd::va_rtti{}); \ + ircd::panicking(*this); \ + } \ + \ + name(generate_skip_t) \ + :parent{generate_skip} \ + { \ + } \ +}; + +namespace ircd +{ + // panic errors; see IRCD_PANICKING docs. + IRCD_PANICKING(exception, panic) + IRCD_PANICKING(panic, not_implemented) +}