gpt4 book ai didi

googletest - 如果抛出异常指针,google test中的EXPECT_THROW能否捕获这个异常?

转载 作者:行者123 更新时间:2023-12-03 18:33:12 34 4
gpt4 key购买 nike

例如,我有一个类似的代码:

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

编译运行后报错:Actual: it throws a different type。

有谁知道答案吗?

谢谢,

最佳答案

你抛出一个指向 myexception 的指针,所以你必须在检查中期待一个指针:

EXPECT_THROW(throw new myexception(), myexception*);

关于googletest - 如果抛出异常指针,google test中的EXPECT_THROW能否捕获这个异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19861977/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com