質問

I'm using googletest and in many of my tests I use the ASSERT_THROW command. The problem is that if, for example, it throws a different exception than the one I expected, all I get is:

Actual: it throws a different type.

Is there some way to get it to spit out the return value of what() or something?

役に立ちましたか?

解決

You probably throw by pointer (using new keyword)

throw new MyDerivedException();

and expected to receive a non-pointer type of exception:

EXPECT_THROW(blah, MyDerivedException);

You should throw by value.

throw MyDerivedException(); // notice lack of 'new'

他のヒント

throw new MyDerivedException() ... EXPECT_THROW(blah, MyDerivedException*);

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top