Is Catching a Null Pointer Exception a Code Smell?
Posted
by Drew
on Stack Overflow
See other posts from Stack Overflow
or by Drew
Published on 2010-04-06T16:00:22Z
Indexed on
2010/04/06
16:03 UTC
Read the original article
Hit count: 214
java
|nullpointerexception
Recently a co-worker of mine wrote in some code to catch a null pointer exception around an entire method, and return a single result. I pointed out how there could've been any number of reasons for the null pointer, so we changed it to a defensive check for the one result.
However, catching NullPointerException just seemed wrong to me. In my mind, Null pointer exceptions are the result of bad code and not to be an expected exception in the system.
Are there any cases where it makes sense to catch a null pointer exception?
© Stack Overflow or respective owner