folly
folly copied to clipboard
Why only SCOPE_SUCCESS macro accepts the default non-noexcept lambda?
In ScopeGuard.h,i can figure out that:
- ExecuteOnException in ScopeGuardForNewException corresponds to InvokeNoexcept in ScopeGuardImpl.
- InvokeNoexcept(true) via SCOPE_EXIT and SCOPE_FAIL makes dtor() and execute() noexcept in ScopeGuardImpl,so after function_ thorws an exception, terminate() will leave a message to cerr, then the whole program will shutdown immediately because noexcept terminate() thorws an exception.
- InvokeNoexcept(false) via SCOPE_SUCCESS removes all noexcept symbols and terminate() will never be called. So dtor() behaves like a normal function_ calling, the throwing exception will be brocasted.
I'm confused that:
- Is the template value ExecuteOnException only affects "noexcept" symbols of the calling-links below and the behaviour when function_ throws an exception ?
ScopeGuardForNewException::dtor()
--> ScopeGuardImpl::dtor()
----> ScopeGuardImpl::execute()
------> ScopeGuardImplBase::terminate() noexcept
- Why makeFailsafe(std::false_type, ...) marks noexcept, seems that ScopeGuardImpl::ctor(...) is inferred non-noexcept ?
- Why SCOPE_EXIT and SCOPE_FAIL macros make noexcept by default but SCOPE_SUCCESS doesn't ?