我不小心将throw
语句粘贴到一个return
之后,导致最终结果如下:
void DXManager::initialize(const std::shared_ptr<nae::Context>& ctx_ptr)
{
// ...
if (FAILED(result))
{
return throw std::exception("Failed to enumerate display mode list");
}
// ...
}
在注意到错误之前,我已经成功构建了解决方案,并且我很好奇哪个规范允许上述语法。
通过阅读cppreference.com(下面的注释),我发现
The throw-expression is classified as prvalue expression of type void. Like any other expression, it may be a sub-expression in another expression, most commonly in the conditional operator:
double f(double d) { return d > 1e7 ? throw std::overflow_error("too big") : d; } // ...
但我不确定它是否符合我的要求。