Methods must not throw RuntimeException
or Exception
. Handling these exceptions requires catching RuntimeException
, which is disallowed by rule ERR14-J. Do not catch NullPointerException or any of its ancestors. Moreover, throwing a RuntimeException
can lead to subtle errors; for example, a caller cannot examine the exception to determine why it was thrown and consequently cannot attempt recovery.
...
A calling method must also violate rule ERR14-J. Do not catch NullPointerException or any of its ancestors to determine if the RuntimeException
was thrown.
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="61965720a03f7156-4501fa19-435e4586-a7fa8ecf-138856b4e86089d75a5c88b6"><ac:plain-text-body><![CDATA[ | [[MITRE 2009 | AA. Bibliography#MITRE 09]] | [CWE-397 | http://cwe.mitre.org/data/definitions/397.html] "Declaration of Throws for Generic Exception" | ]]></ac:plain-text-body></ac:structured-macro> |
| CWE-537 "Information Exposure Through Java Runtime Error Message" |
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="342ac2a52432a152-575b4ea7-42a44c2a-a339ab30-1f8116bb2a55cbb423e45ecb"><ac:plain-text-body><![CDATA[ | [[Goetz 2004b | AA. Bibliography#Goetz 04b]] |
| ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="3e2ee44fdfb353dd-bf2e4060-40ed40bc-8f47a060-9d8eeb9c824ff0c377f8f91b"><ac:plain-text-body><![CDATA[ | [[Tutorials 2008 | AA. Bibliography#Tutorials 08]] | [Unchecked Exceptions — The Controversy | http://java.sun.com/docs/books/tutorial/essential/exceptions/runtime.html] | ]]></ac:plain-text-body></ac:structured-macro> |
...
06. Exceptional Behavior (ERR) ERR14-J. Do not catch NullPointerException or any of its ancestors