[snip]
I think the problem is more a matter of software knowing when overflow
should and should not be treated as an error.
Exactly. C does not do that sort of checking, and the meme has
spread widely. I would much prefer to have things blow up when wrong
than not blow up. It makes for smaller messes.
the problem with that statement is that it's not wrong for Java
primitive integer types to wrap around.
Java is designed to behave that way. That does not mean that it
is not wrong.
It doesn't mean that it is wrong.
In fact, it does mean that it's not wrong. If you're working in Java,
to do differently from what the Java spec requires is wrong.
As others have pointed out, there's an awful lot of code that depends
on the documented, required behavior. For that code, to have overflow
exceptions would be wrong, doubly so because it would violate the
rules under which the code was developed.
A garrot is designed to be a murder weapon. That it was designed
for that does not make any murder committed with a garrot any less
wrong.
A useless analogy that adds no insight to the question of overflow
exceptions. There is no evidence that wrapping around overflow is
equivalent to a murder weapon other than your fanciful rhetoric.
It is designed to behave like that. That behaviour is often
wrong from the point of view of ensuring program correctness.
Much more often, in Java, the behavior is right from the point of view
of ensuring program correctness, because Java programs are written
with the required behavior in mind.
C allows wraparound with unsigned (which I wish Java had)
integers. An overflow with signed integers results in undefined
behaviour. C's semantics are better than those of Java in this
regard. They should be better: throw an error.
"should" is pretty useless here - Java should do what it's documented
to do.
There are programmatic workarounds for preventing wraparound, and no
doubt there are errors that arise from the lack of overflow exception
trapping, just as there would be errors possible from its presence.
You have a personal preference to trap overflow exceptions, which you
like to present as an absolute rule for all programmers. that doesn't
make your personal preference better, just yours. You've offered no
objective evidence that your preference would be better for anyone
besides yourself; others here have offered evidence that to change
Java's behavior would cause more errors than your idea would fix.
I fully support your right to have a personal preference.