Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If an exception pointer is thrown, can EXPECT_THROW in google test capture this exception?

Tags:

googletest

For example, I have a code like:

TEST_F(Testmyexception, testthrownexception)
{
  EXPECT_THROW(throw new myexception(), myexception);
} 

After compiling and running, it gives an error: Actual: it throws a different type.

Does anynone know the answer?

Thanks,

like image 432
JerryLi Avatar asked Dec 09 '22 11:12

JerryLi


1 Answers

You're throwing a pointer to a myexception, so you have to expect a pointer in the check:

EXPECT_THROW(throw new myexception(), myexception*);
like image 124
Fraser Avatar answered Apr 06 '23 00:04

Fraser