google / google/googletest

Exception inside ON_CALL will not be catched

Open
#3,975 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
C++
Stars
39.5k
Forks
10.9k
Avg merge
6d 13h
Merged PRs (30d)
1

Description

Hi,

When I use ON_CALL with WillByDefault and try to throw exception inside it, that will not be catched by EXPECT_THROW. Also I am getting an error which says that exception was thrown during tests.

For example:

**MockClass**
```cpp
class MockClass : public SomeClass
{
public:
MOCK_METHOD(void, someFunction, (), (override);
}
```

**MockClassTests**
```cpp
TEST
{
MockClass mock;

ON_CALL(mock, someFunction).WillByDefault([]() {
throw std::runtime_error{"error message"};
});

EXPECT_THROW(mock.someFunction(), std::runtime_error);
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.