Wiki Markup |
---|
Programs must not catch {{java.lang.NullPointerException}}. A {{NullPointerException}} exception thrown at runtime indicates the existence of an underlying {{null}} pointer dereference that must be fixed in the application code (see [EXP11-J. Never dereference null pointers|EXP11-J. Never dereference null pointers]). Handling the underlying null pointer dereference by catching the {{NullPointerException}} rather than fixing the underlying problem is inappropriate for several reasons. First, _avoiding_ the exception by catching {{NullPointerException}} adds significantly more performance overhead than simply adding the necessary checks \[[Bloch 2008|AA. Bibliography#Bloch 08]\]. Second, when there are multiple expressions in a {{try}} block that are capable of throwing a {{NullPointerException}}, it is difficult or impossible to determine which expression is responsible for the exception because the {{NullPointerException}} {{catch}} block handles any {{NullPointerException}} thrown from any location in the {{try}} block. Third, programs rarely remain in an expected and usable state after a {{NullPointerException}} has been thrown. Attempts to continue execution after first catching and logging (or worse, suppressing) the exception rarely succeed. |
...
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="5b17ff8ecf9143c2-4cb8dbe8-46d548d4-bebba0fc-2d4f80d5adea6c59a44b80b7"><ac:plain-text-body><![CDATA[ | [[Cunningham 1995 | AA. Bibliography#Cunningham 95]] |
| ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="18f90cdbf7fbc7ac-6d5082be-442b4b89-acd1a898-4583b56fa5c12b89c7e29760"><ac:plain-text-body><![CDATA[ | [[Doshi 2003 | AA. Bibliography#Doshi 03]] |
| ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="2e391b9229df4b20-63e282b5-4b684071-96bf95e6-abf41de060b02060210021da"><ac:plain-text-body><![CDATA[ | [[Grand 2002 | AA. Bibliography#Grand 02]] | Chapter 8, Behavioral patterns, the Null Object | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="11d3810a68d85b09-a26d90c3-42794262-a07aa71a-8f8b70d519b324856228fbde"><ac:plain-text-body><![CDATA[ | [[Henney 2003 | AA. Bibliography#Henney 03]] |
| ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="923737560e40979f-f311e121-45934a83-9f09b65f-615b73a7e46d03f954eece06"><ac:plain-text-body><![CDATA[ | [[JLS 2005 | AA. Bibliography#JLS 05]] | [Chapter 11, Exceptions | http://java.sun.com/docs/books/jls/third_edition/html/exceptions.html] | ]]></ac:plain-text-body></ac:structured-macro> |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="7dfd79d35ba5c0ad-db80baf1-48c24c5c-87639574-367e96340156bbdef2928ef5"><ac:plain-text-body><![CDATA[ | [[J2SE 2011 | AA. Bibliography#J2SE 11]] | Catching Multiple Exception Types and Rethrowing Exceptions with Improved Type Checking | ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="c10fd7bbf4740707-5ce2a865-469243ac-bc339e74-39052950716c08d2dfa700db"><ac:plain-text-body><![CDATA[ | [[Muller 2002 | AA. Bibliography#Muller 02]] |
| ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="646c927fc25a2a09-e94ec498-47a142d5-86a3b416-3b12087e273fe390491f2010"><ac:plain-text-body><![CDATA[ | [[Schweisguth 2003 | AA. Bibliography#Schweisguth 03]] |
| ]]></ac:plain-text-body></ac:structured-macro> | |
<ac:structured-macro ac:name="unmigrated-wiki-markup" ac:schema-version="1" ac:macro-id="c62788afdcc32c26-f943255b-484149e3-887d9dde-9f758799c5f6d47125cfb33b"><ac:plain-text-body><![CDATA[ | [[Tutorials 2008 | AA. Bibliography#tutorials 08]] | [Exceptions | http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html] | ]]></ac:plain-text-body></ac:structured-macro> |
...
ERR13-J. Do not throw RuntimeException, Exception, or Throwable 06. Exceptional Behavior (ERR) void ERR15-J. Do not catch NullPointerException07. Visibility and Atomicity (VNA)