Re: Checking for null parameter
- From: pek <kimwlias@xxxxxxxxx>
- Date: Tue, 10 Jun 2008 17:55:39 -0700 (PDT)
On Jun 11, 3:40 am, Lew <con...@xxxxxxxxxxxxxxxxxxxxx> wrote:
pek wrote:
I'm also curious about what you would suggest doing in printLength thatYou are arguing against points that I have not made and with which I
would prevent a crash when a null is passed in. Presumably, i [sic] test for
null, or catch the NullPointerException - but what do i do then? Skip the
printing? Print 0? Print an error message? I'd say that the program is
then behaving incorrectly, which is worse than crashing. Should it throw
an unchecked exception? Then it merely crashes in a different way. Should
it throw a checked exception? What could the calling code do with that
that isn't ultimately also crashing?
do not agree. Why would I defend points with which I do not agree?
That is not an answer to his question. What would you do in this
situation? I am also curious. His point, I believe and agree, is
either way you choose to go, you still have to fix the point at which
a null reference is passed, thus, checking for it isn't going to
change anything.
Your statement makes no sense. How can you fix what you can't detect? In
order to fix the null reference, you have to find it, which means you have to
check for it. How else do you find it?
What is the difference of reading what you logged and reading the
stack trace of a NPE? In both cases, you can find it.
I suggest that one catch and log the exception. If you prevent the exception,
which is usually better, then catch and log the illegal situation such as null
input. Then restore the program to valid state, commonly a retry of the
input. Is that not the obvious approach?
How do you prevent an exception? By checking if the object is null
before calling a method? How is that preventing? What will it do after
not calling the method? Inform the user for an abnormal situtation and
then close? Isn't this the same thing as if a NPE was thrown? Why even
bother? Because in any case, your code has a bug. Either way, the
program must end because the method wasn't executaded as it had to.
--
Lew
.
- Follow-Ups:
- Re: Checking for null parameter
- From: Lew
- Re: Checking for null parameter
- From: Lew
- Re: Checking for null parameter
- References:
- Checking for null parameter
- From: pek
- Re: Checking for null parameter
- From: Lew
- Re: Checking for null parameter
- From: Tom Anderson
- Re: Checking for null parameter
- From: Lew
- Re: Checking for null parameter
- From: Tom Anderson
- Re: Checking for null parameter
- From: Lew
- Re: Checking for null parameter
- From: pek
- Re: Checking for null parameter
- From: Lew
- Checking for null parameter
- Prev by Date: Re: Checking for null parameter
- Next by Date: Re: Checking for null parameter
- Previous by thread: Re: Checking for null parameter
- Next by thread: Re: Checking for null parameter
- Index(es):
Relevant Pages
|
|