主要内容

C++ 异常缺陷

与 C++ 异常及其处理相关的缺陷,例如,noexcept 函数中未处理的异常,或由 throw 语句引发的意外异常

这些缺陷与 C++ 异常处理相关。这些缺陷包括:

  • noexcept 函数发出的未处理的异常

  • 在构造 throw 语句的参量对象时出现的意外异常

  • 按值而非按引用捕获异常的 catch 语句

  • 隐藏后续 catch 语句的 catch 语句

Polyspace 结果

按值捕获异常catch statement accepts an object by value
异常处理程序被上一处理程序隐藏catch statement is not reached because of an earlier catch statement for the same exception
Noexcept 函数因异常而退出Functions specified as noexcept, noexcept(true) or noexcept(<true condition>) exits with an exception, which causes abnormal termination of program execution, leading to resource leak and security vulnerability
Throw 参量出现意外异常The argument expression in a throw statement raises unexpected exceptions, leading to resource leaks and security vulnerabilities
未捕获异常An exception is raised from a function but it is not caught and handled (自 R2022b 起)
Throw 参量表达式调用 newThe argument expression in a throw statement allocates memory by calling new, which can result in abrupt termination of the program and resource leaks (自 R2023b 起)

主题