From ed84fc4e2376dae2bfcb4831b7e696132ac9b71b Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 15 Feb 2022 01:51:15 +0200 Subject: [PATCH] Document verbose_terminate_handler --- doc/core.qbk | 3 +- doc/verbose_terminate_handler.qbk | 70 +++++++++++++++++++ .../boost/core/verbose_terminate_handler.hpp | 2 +- 3 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 doc/verbose_terminate_handler.qbk diff --git a/doc/core.qbk b/doc/core.qbk index fbbecf6..33e2faf 100644 --- a/doc/core.qbk +++ b/doc/core.qbk @@ -34,7 +34,7 @@ criteria for inclusion is that the utility component be: * simple, * used by other Boost libraries, and * not dependent on any other Boost modules except Core - itself, Config, Assert, or Static Assert. + itself, Config, Assert, StaticAssert, or ThrowException. [endsect] @@ -72,3 +72,4 @@ criteria for inclusion is that the utility component be: [include type_name.qbk] [include uncaught_exceptions.qbk] [include use_default.qbk] +[include verbose_terminate_handler.qbk] diff --git a/doc/verbose_terminate_handler.qbk b/doc/verbose_terminate_handler.qbk new file mode 100644 index 0000000..35f8bff --- /dev/null +++ b/doc/verbose_terminate_handler.qbk @@ -0,0 +1,70 @@ +[/ + Copyright 2022 Peter Dimov + Distributed under the Boost Software License, Version 1.0. + https://boost.org/LICENSE_1_0.txt +] + +[section:verbose_terminate_handler verbose_terminate_handler] + +[simplesect Authors] + +* Peter Dimov + +[endsimplesect] + +[section Header ] + +The header `` defines +the function `void boost::core::verbose_terminate_handler()`. Its +purpose is to be set as a terminate handler as in +``` + std::set_terminate( boost::core::verbose_terminate_handler ); +``` + +When invoked, the function prints information about the current +uncaught exception to `stderr` and then calls `std::abort`. + +[section Synopsis] + +`` +namespace boost +{ +namespace core +{ + +[[noreturn]] void verbose_terminate_handler(); + +} // namespace core +} // namespace boost +`` + +[endsect] + +[section Example] + +``` +#include +#include +#include + +int main() +{ + std::set_terminate( boost::core::verbose_terminate_handler ); + boost::throw_with_location( std::exception() ); +} +``` + +Sample output: +``` +std::terminate called after throwing an exception: + + type: class boost::detail::with_throw_location + what(): Unknown exception + location: example.cpp:8:12 in function 'main' +``` + +[endsect] + +[endsect] + +[endsect] diff --git a/include/boost/core/verbose_terminate_handler.hpp b/include/boost/core/verbose_terminate_handler.hpp index b831b49..408b12e 100644 --- a/include/boost/core/verbose_terminate_handler.hpp +++ b/include/boost/core/verbose_terminate_handler.hpp @@ -60,7 +60,7 @@ BOOST_NORETURN void verbose_terminate_handler() boost::source_location loc = boost::get_throw_location( x ); std::fprintf( stderr, - "std::terminate called after throwing an exception:\n" + "std::terminate called after throwing an exception:\n\n" " type: %s\n" " what(): %s\n" " location: %s:%lu:%lu in function '%s'\n",