28class ScopeGuard
final {
30 using Callback = std::function<
void()>;
32 explicit ScopeGuard(Callback callback)
33 : callback_(std::move(callback)),
34 exceptions_on_enter_(std::uncaught_exceptions())
37 ScopeGuard(
const ScopeGuard&) =
delete;
38 ScopeGuard(ScopeGuard&&) =
delete;
40 ScopeGuard& operator=(
const ScopeGuard&) =
delete;
41 ScopeGuard& operator=(ScopeGuard&&) =
delete;
43 ~ScopeGuard()
noexcept(
false) {
48 if (std::uncaught_exceptions() != exceptions_on_enter_) {
52 }
catch (
const std::exception& e) {
53 UASSERT_MSG(
false,
"exception is thrown during stack unwinding");
54 LOG_ERROR() <<
"Exception is thrown during stack unwinding - ignoring: " << e;
62 void Release()
noexcept { callback_ = {}; }
66 const int exceptions_on_enter_;