diff --git a/include/boost/leaf/exception.hpp b/include/boost/leaf/exception.hpp index 362e753d..240e68cb 100644 --- a/include/boost/leaf/exception.hpp +++ b/include/boost/leaf/exception.hpp @@ -85,6 +85,11 @@ namespace leaf_detail { mutable bool clear_current_error_; + bool is_current_exception() const noexcept + { + return tls::read_uint() == error_id::value(); + } + error_id get_error_id() const noexcept final override { clear_current_error_ = false; @@ -143,7 +148,7 @@ namespace leaf_detail ~exception() noexcept { - if( clear_current_error_ ) + if( clear_current_error_ && is_current_exception() ) tls::write_uint(0); } };