Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Wiki Markup
A method should rarely throw {{RuntimeException}} or {{Exception}}. This is because handling these exceptions requires catching {{RuntimeException}}, which is forbidden in guideline [EXC14-J. Catch specific exceptions as opposed to the more general RuntimeException or Exception]. Moreover, throwing a {{RuntimeException}} can lead to subtle errors, for instance, a caller who fails to retrieve a return value from an offending method is unable to check for appropriate feedback. The Java Language Specification (Section 8.4.7 Method Body) allows the declaration of a method with a return type without making it necessary to return a value if a runtime exception is thrown from within the method \[[JLS 2005|AA. Bibliography#JLS 05]\].

...

To handle the case of passing in a null string parameter, code calling this method may require catching RuntimeException, which is a violation of guideline EXC14-J. Catch specific exceptions as opposed to the more general RuntimeException or Exception.

...

Throwing RuntimeException and Exception prevents classes from catching the intended exceptions without catching other unintended exceptions as well.

Rule Guideline

Severity

Likelihood

Remediation Cost

Priority

Level

EXC13-J

low

likely

medium

P6

L2

...