☰
  • 首页
  • 规则分类
  • 项目介绍
search
•••

捕获异常后不应直接再次抛出异常

7.21 ID_catch_justRethrow
目录 › next › previous

捕获异常后将其直接再次抛出是没有意义的,还会造成不必要的开销。

示例:

void foo() {
    try {
        bar();
    }
    catch (...) {
        throw;      // Non-compliant
    }
}

例中 catch 子句是没有意义的,往往是残留代码或功能不完整的代码,应将其去掉或对异常进行有效处理。

Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.