I’m using gtest for testing my code base, I need to override mock function to throw exception as follow:
ACTION(MyThrowException)
{
throw std::runtime_error ("run time error") ;
}
TEST_F(MyTest, MyUT)
{
ON_CALL(*mockObj, mockMethod()).WillByDefault(MyThrowException());
myAppPtr->Start();
}
in Start function in my solution, I’m trying to catch the exception as follow:
try
{
obj.mockMethod();
}
catch(const std::runtime_error& e){
std::cout<<e.what()<<std::endl;
}
catch (...)
{
std::cout<<e.what()<<std::endl;
}
but every time the exception didn’t caught and I got : terminate called after throwing an instance of ‘std::runtime_error
how can I trace such issue?