Declaration of Catch for Generic Exception |
Weakness ID: 396 (Weakness Base) | Status: Draft |
Description Summary
Extended Description
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.
Example 1
The following code excerpt handles three types of exceptions in an identical fashion.
At first blush, it may seem preferable to deal with these exceptions in a single catch block, as follows:
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.
Nature | Type | ID | Name | View(s) this relationship pertains to |
---|---|---|---|---|
ChildOf | Weakness Class | 221 | Information Loss or Omission | Research Concepts1000 |
ChildOf | Category | 388 | Error Handling | Seven Pernicious Kingdoms (primary)700 |
ChildOf | Category | 389 | Error Conditions, Return Values, Status Codes | Development Concepts (primary)699 |
ChildOf | Weakness Class | 705 | Incorrect Control Flow Scoping | Research Concepts (primary)1000 |
ChildOf | Weakness Class | 755 | Improper Handling of Exceptional Conditions | Research Concepts1000 |
Mapped Taxonomy Name | Node ID | Fit | Mapped Node Name |
---|---|---|---|
7 Pernicious Kingdoms | Overly-Broad Catch Block |
Submissions | ||||
---|---|---|---|---|
Submission Date | Submitter | Organization | Source | |
7 Pernicious Kingdoms | Externally Mined | |||
Modifications | ||||
Modification Date | Modifier | Organization | Source | |
2008-07-01 | Eric Dalci | Cigital | External | |
updated Time of Introduction | ||||
2008-09-08 | CWE Content Team | MITRE | Internal | |
updated Applicable Platforms, Relationships, Other Notes, Taxonomy Mappings | ||||
2008-09-24 | CWE Content Team | MITRE | Internal | |
Removed C from Applicable Platforms | ||||
2008-10-14 | CWE Content Team | MITRE | Internal | |
updated Applicable Platforms | ||||
2009-03-10 | CWE Content Team | MITRE | Internal | |
updated Relationships | ||||
2009-05-27 | CWE Content Team | MITRE | Internal | |
updated Demonstrative Examples | ||||
2009-10-29 | CWE Content Team | MITRE | Internal | |
updated Description, Other Notes | ||||
Previous Entry Names | ||||
Change Date | Previous Entry Name | |||
2008-04-11 | Overly-Broad Catch Block | |||