Skip to content
This repository was archived by the owner on Jul 17, 2019. It is now read-only.

Don't throw nested exception from dtor of Mock object #206

Open
rgolovanov opened this issue May 18, 2017 · 0 comments
Open

Don't throw nested exception from dtor of Mock object #206

rgolovanov opened this issue May 18, 2017 · 0 comments

Comments

@rgolovanov
Copy link

There is a problem I met using GMock with 3rdParty UT-engine based on exceptions handling.

If I enables throwing exceptions from GMock: ::testing::GTEST_FLAG(throw_on_failure) = true
Then in test case if I created a local Mock object with invalid expectation call then I will get exception in exception:

  1. Because of invalid arguments passed to the method.
  2. During stack unwinding we will destroy Mock object and will call VerifyAndClearExpectationsLocked(); from~FunctionMockerBase()

These behavior obviously leads to process termination.

The suggestion is to check whether we already in unhandled exception or not before Verifing expectations in destructor:

    if (!std::uncaught_exception())
    {
       VerifyAndClearExpectationsLocked();
    }
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant