, exceptionCounter_(std::move(other.exceptionCounter_)) {
}
- ~ScopeGuardForNewException() noexcept {
+ ~ScopeGuardForNewException() noexcept(executeOnException) {
if (executeOnException == exceptionCounter_.isNewUncaughtException()) {
- execute();
+ function_();
}
}
void* operator new(size_t) = delete;
- void execute() noexcept { function_(); }
-
FunctionType function_;
UncaughtExceptionCounter exceptionCounter_;
};
#define SCOPE_EXIT \
auto FB_ANONYMOUS_VARIABLE(SCOPE_EXIT_STATE) \
- = ::folly::detail::ScopeGuardOnExit() + [&]
+ = ::folly::detail::ScopeGuardOnExit() + [&]() noexcept
#if defined(FOLLY_EXCEPTION_COUNT_USE_CXA_GET_GLOBALS) || \
defined(FOLLY_EXCEPTION_COUNT_USE_GETPTD)
#define SCOPE_FAIL \
auto FB_ANONYMOUS_VARIABLE(SCOPE_FAIL_STATE) \
- = ::folly::detail::ScopeGuardOnFail() + [&]
+ = ::folly::detail::ScopeGuardOnFail() + [&]() noexcept
#define SCOPE_SUCCESS \
auto FB_ANONYMOUS_VARIABLE(SCOPE_SUCCESS_STATE) \
- = ::folly::detail::ScopeGuardOnSuccess() + [&]
+ = ::folly::detail::ScopeGuardOnSuccess() + [&]()
#endif // native uncaught_exception() supported
#endif // FOLLY_SCOPEGUARD_H_
testScopeFailAndScopeSuccess(ErrorBehavior::UNHANDLED_ERROR, true);
}
+TEST(ScopeGuard, TEST_SCOPE_SUCCESS_THROW) {
+ auto lambda = []() {
+ SCOPE_SUCCESS { throw std::runtime_error("ehm"); };
+ };
+ EXPECT_THROW(lambda(), std::runtime_error);
+}
+
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
google::ParseCommandLineFlags(&argc, &argv, true);