Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get google test exception throw message [duplicate]

I am using google Test framework for my project. I am throwing exception from the code as:

throw DerivedClassException("message");  

and in the test frame using as:

ASSERT_THROW(commond(), DerivedClassException);  

I want to get message with what() API. Any way to get exact exception message of the exception.

like image 540
anurudh Avatar asked Apr 08 '15 05:04

anurudh


1 Answers

The only way to check the thrown exception is to catch it in the test :

void test_foo( MyTest, TestException )
{
  try
  {
    functionThatThrowsException();
    FAIL();
  }
  catch( const DerivedClassException& err )
  {
    // check exception
    ASSERT_STREQ( "error message", err.what() );
  }
}
like image 155
BЈовић Avatar answered Sep 29 '22 13:09

BЈовић