结构: Simple
Abstraction: Base
状态: Draft
被利用可能性: unkown
Catching overly broad exceptions promotes complex error handling code that is more likely to contain security vulnerabilities.
Multiple catch blocks can get ugly and repetitive, but "condensing" catch blocks by catching a high-level class like Exception can obscure exceptions that deserve special treatment or that should not be caught at this point in the program. Catching an overly broad exception essentially defeats the purpose of Java's typed exceptions, and can become particularly dangerous if the program grows and begins to throw new types of exceptions. The new exception types will not receive any attention.
cwe_Nature: ChildOf cwe_CWE_ID: 705 cwe_View_ID: 1000 cwe_Ordinal: Primary
cwe_Nature: ChildOf cwe_CWE_ID: 755 cwe_View_ID: 1000
cwe_Nature: ChildOf cwe_CWE_ID: 221 cwe_View_ID: 1000
Language: [{'cwe_Name': 'C++', 'cwe_Prevalence': 'Undetermined'}, {'cwe_Name': 'Java', 'cwe_Prevalence': 'Undetermined'}, {'cwe_Name': 'C#', 'cwe_Prevalence': 'Undetermined'}]
范围 | 影响 | 注释 |
---|---|---|
['Non-Repudiation', 'Other'] | ['Hide Activities', 'Alter Execution Logic'] |
The following code excerpt handles three types of exceptions in an identical fashion.
good Java
At first blush, it may seem preferable to deal with these exceptions in a single catch block, as follows:
bad
However, if doExchange() is modified to throw a new type of exception that should be handled in some different kind of way, the broad catch block will prevent the compiler from pointing out the situation. Further, the new catch block will now also handle exceptions derived from RuntimeException such as ClassCastException, and NullPointerException, which is not the programmer's intent.
映射的分类名 | ImNode ID | Fit | Mapped Node Name |
---|---|---|---|
7 Pernicious Kingdoms | Overly-Broad Catch Block | ||
Software Fault Patterns | SFP5 | Ambiguous Exception Type | |
OMG ASCSM | ASCSM-CWE-396 | ||
OMG ASCRM | ASCRM-CWE-396 |