CodeQL 文档

意外重新抛出

ID: cpp/rethrow-no-exception
Kind: problem
Security severity: 
Severity: warning
Precision: high
Tags:
   - reliability
   - correctness
   - exceptions
Query suites:
   - cpp-security-and-quality.qls

单击查看 CodeQL 代码库中的查询

C++ throw 表达式可以采用多种形式。一种形式抛出一个新的异常,而另一种形式则重新抛出当前异常。在后一种情况下,如果当前没有异常,则程序将终止。在异常处理上下文之外存在重新抛出操作通常是由于程序员不知道要抛出哪种异常。

建议

throw 表达式更改为抛出特定类型的异常。

示例

void bad() {
  /* ... */
  if(error_condition)
    throw;
}

void good() {
  /* ... */
  if(error_condition)
    throw std::exception("Something went wrong.");
}

参考

  • ©GitHub, Inc.
  • 条款
  • 隐私