Declaration of Throws for Generic Exception |
Weakness ID: 397 (Weakness Base) | Status: Draft |
Description Summary
Extended Description
Declaring a method to throw Exception or Throwable makes it difficult for callers to perform proper error handling and error recovery. Java's exception mechanism, for example, is set up to make it easy for callers to anticipate what can go wrong and write code to handle each specific exceptional circumstance. Declaring that a method throws a generic form of exception defeats this system.
Example 1
The following method throws three types of exceptions.
While it might seem tidier to write
doing so hampers the caller's ability to understand and handle the exceptions that occur. Further, if a later revision of doExchange() introduces a new type of exception that should be treated differently than previous exceptions, there is no easy way to enforce this requirement.
Nature | Type | ID | Name | View(s) this relationship pertains to![]() |
---|---|---|---|---|
ChildOf | ![]() | 221 | Information Loss or Omission | Research Concepts1000 |
ChildOf | ![]() | 388 | Error Handling | Seven Pernicious Kingdoms (primary)700 |
ChildOf | ![]() | 389 | Error Conditions, Return Values, Status Codes | Development Concepts (primary)699 |
ChildOf | ![]() | 703 | Failure to Handle Exceptional Conditions | Research Concepts1000 |
ChildOf | ![]() | 705 | Incorrect Control Flow Scoping | Research Concepts (primary)1000 |
Mapped Taxonomy Name | Node ID | Fit | Mapped Node Name |
---|---|---|---|
7 Pernicious Kingdoms | Overly-Broad Throws Declaration |
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 Throws Declaration | |||