folly icon indicating copy to clipboard operation
folly copied to clipboard

Why only SCOPE_SUCCESS macro accepts the default non-noexcept lambda?

Open JingLiofLiJing opened this issue 4 years ago • 0 comments

In ScopeGuard.h,i can figure out that:

  1. ExecuteOnException in ScopeGuardForNewException corresponds to InvokeNoexcept in ScopeGuardImpl.
  2. 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.
  3. 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:

  1. 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
  1. Why makeFailsafe(std::false_type, ...) marks noexcept, seems that ScopeGuardImpl::ctor(...) is inferred non-noexcept ?
  2. Why SCOPE_EXIT and SCOPE_FAIL macros make noexcept by default but SCOPE_SUCCESS doesn't ?

JingLiofLiJing avatar Feb 16 '22 08:02 JingLiofLiJing