From 08899052adcddb8ebd4cfc1f69edd11c5b54edea Mon Sep 17 00:00:00 2001 From: Zygo Blaxell Date: Wed, 2 Jun 2021 12:17:11 -0400 Subject: [PATCH] trace: current_exception() is not a replacement for uncaught_exception() In 15ab981d9e "bees: replace uncaught_exception(), deprecated in C++17", uncaught_exception() was replaced with current_exception(); however, current_exception() is only valid after an exception has been captured by a catch block. BeesTracer wants to know about exceptions _before_ they are caught, so current_exception() is not useful here. Instead, conditionally compile using uncaught_exception() or uncaught_exceptions(), selected by C++ standard version, and make bees stack traces work again. Fixes: 15ab981d9e "bees: replace uncaught_exception(), deprecated in C++17" Signed-off-by: Zygo Blaxell --- src/bees-trace.cc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/bees-trace.cc b/src/bees-trace.cc index 7d0d374..9e9c71f 100644 --- a/src/bees-trace.cc +++ b/src/bees-trace.cc @@ -8,9 +8,25 @@ thread_local BeesTracer *BeesTracer::tl_next_tracer = nullptr; thread_local bool BeesTracer::tl_first = true; thread_local bool BeesTracer::tl_silent = false; +#if __cplusplus >= 201703 +static +bool +exception_check() +{ + return uncaught_exceptions(); +} +#else +static +bool +exception_check() +{ + return uncaught_exception(); +} +#endif + BeesTracer::~BeesTracer() { - if (!tl_silent && current_exception()) { + if (!tl_silent && exception_check()) { if (tl_first) { BEESLOGNOTICE("--- BEGIN TRACE --- exception ---"); tl_first = false;