0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-12 04:51:08 +01:00

ircd: Split panic/terminate exception related into header.

This commit is contained in:
Jason Volk 2020-02-26 11:57:54 -08:00
parent 72b772b530
commit 139059f381
3 changed files with 71 additions and 51 deletions

View file

@ -22,7 +22,6 @@ namespace boost::system
namespace ircd namespace ircd
{ {
struct terminate;
struct exception; // Root exception struct exception; // Root exception
// util // util
@ -53,10 +52,6 @@ namespace ircd
std::string string(const std::system_error &); std::string string(const std::system_error &);
std::string string(const boost::system::error_code &); std::string string(const boost::system::error_code &);
std::string string(const boost::system::system_error &); 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. /// The root exception type.
@ -112,15 +107,6 @@ struct ircd::exception
exception &operator=(const exception &) = delete; 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 /// Exception generator convenience macro
/// ///
/// If you want to create your own exception type, you have found the right /// 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<class... args> \
name(const string_view &fmt, args&&... ap) noexcept \
:parent{generate_skip} \
{ \
generate(#name, fmt, ircd::va_rtti{std::forward<args>(ap)...}); \
ircd::panicking(*this); \
} \
\
template<class... args> \
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 namespace ircd
{ {
/// Root error exception type. Inherit from this. /// Root error exception type. Inherit from this.
@ -258,10 +211,6 @@ namespace ircd
/// ///
IRCD_EXCEPTION(exception, error) // throw ircd::error("something bad") IRCD_EXCEPTION(exception, error) // throw ircd::error("something bad")
IRCD_EXCEPTION(error, user_error) // throw ircd::user_error("something silly") 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<class E, template<class E,

View file

@ -48,6 +48,7 @@
#include "allocator.h" #include "allocator.h"
#include "util/util.h" #include "util/util.h"
#include "exception.h" #include "exception.h"
#include "panic.h"
#include "run.h" #include "run.h"
#include "demangle.h" #include "demangle.h"
#include "backtrace.h" #include "backtrace.h"

70
include/ircd/panic.h Normal file
View file

@ -0,0 +1,70 @@
// The Construct
//
// Copyright (C) The Construct Developers, Authors & Contributors
// Copyright (C) 2016-2020 Jason Volk <jason@zemos.net>
//
// 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<class... args> \
name(const string_view &fmt, args&&... ap) noexcept \
:parent{generate_skip} \
{ \
generate(#name, fmt, ircd::va_rtti{std::forward<args>(ap)...}); \
ircd::panicking(*this); \
} \
\
template<class... args> \
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)
}