NullPointerException, IllegalArgumentException, or AssertionErrorfor null constructor argument

L

Lew

Whoops! That should have been "RAM".

Please refresh our collective memories on this matter. I for one am quite
interested. Why did people complain about parity-checked RAM? Do they still,
and if not, why not?

A few words of how that ties in might not be remiss.
 
P

Patricia Shanahan

Lew said:
Please refresh our collective memories on this matter. I for one am
quite interested. Why did people complain about parity-checked RAM? Do
they still, and if not, why not?

A few words of how that ties in might not be remiss.

The problem with parity, as distinct from ECC, is that all you can do if
it detects an error is abort anything that is affected by the location
showing the error. However, arguably that is better than not having any
error detection. In most cases, a wrong answer is worse than an abort.

Patricia
 
J

John W. Kennedy

Lew said:
Please refresh our collective memories on this matter. I for one am
quite interested. Why did people complain about parity-checked RAM? Do
they still, and if not, why not?

A few words of how that ties in might not be remiss.

Weren't you on-line in the mid-80s? "I don't want this dumb parity
checking; it makes my system crash," was even more popular than, "My
computer must be broken, because 1/3 + 1/3 + 1/3 is coming out 0.999999
instead of 1.0."

--
John W. Kennedy
"There are those who argue that everything breaks even in this old dump
of a world of ours. I suppose these ginks who argue that way hold that
because the rich man gets ice in the summer and the poor man gets it in
the winter things are breaking even for both. Maybe so, but I'll swear I
can't see it that way."
-- The last words of Bat Masterson
 
L

Lew

Daniel said:
I have a constructor that takes a String argument. I'd like to throw an
exception if the constructor is invoked with a null argument, but I'm
not sure which instruction I should use.
NullPointerException is technically accurate, since it is a null
pointer, but it is also an IllegalArgumentException. I think that
IllegalArgumentException is more specific, so I'll probably go with
that, but wanted opinions.

The third option is AssertionError. I could just use assert arg!=null,
and that could be enough. This is for a personal project, so it doesn't
*really* matter, but at the same time its good practice for me to think
about these sort of things :)

Thoughts?

Here's an example of the difference between assertion and exception
generation. The assertion is forced to hold by the exception handling. If
the exception-handling algorithm were wrong, the null could perhaps slip
through, and the assert would fail. This should never happen.

The assert is there to alert us if the exception failed to do its job. The
programmer is asserting that the exception clause is sufficient.

public class NoNullHolder <T>
{
private final T held;

public NoNullHolder( T toHold )
{
if ( toHold == null )
{
throw new IllegalArgumentException( new NullPointerException(
"null toHold" ));
}
held = toHold;
assert held != null; // postcondition invariant
}

public final T getHeld()
{
assert held != null; // precondition invariant
return held;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top