Re: Exception questions
(Please trim your posts.)
Actually, I would but in other threads people have said they're leaving
theirs intact for the benefit of those using Google groups. Won't I be
preventing Google Groups users from benefitting from this discussion if I
trim my posts?
No, quite the contrary. And so what if you did?
As I mentioned in the original post, the year 0 never happened - the
calendar went straight from the year 1 BC to 1 AD. Therefore, if someone
put "0" (or "00" or "000" or "0000") in a form that asked for a year,
they'd be inputting an invalid year.
The year 1 never happened either. Neither did the year 100. Are you
going to reject those years, too?
Note, again, that the standard Java API does accept the year 0,
because it uses the proleptic Gregorian calendar.
Are you going to reject October 10, 1582? That only happened some
places. Are you going to consider February 28, 1560, to be in the
same year as October 28, 1560? That would be wrong. Do you consider
that Cervantes and Shakespeare died on the same day because they died
on the same date, even though they died ten days apart?
Just out of curiosity:
- Why not just use 'GregorianCalendar#isLeapYear(int year)'? FWIW,
that method takes 0 as a legitimate argument, signifying BC 1.
Huh? Interpreting 0 as BC 1 makes no sense to me.
That's because you haven't studied calendars very much, and apparently
haven't bothered to read the Javadocs very much either.
- Are you going to reject dates prior to 1582 in the Catholic world,
1700 in Scandinavia, 1753 in Sweden or 1752 in the former British
Who said anything about rejecting those dates?
Well, they didn't happen in the Gregorian calendar. Why wouldn't you
And am I not permitted to introduce a new concept, or must everything
I suggest have been brought up already before I comment?
- Are you aware that New Year's Day was on March 25 prior to the
adoption of the Gregorian calendar? (You would be if you read
Yes, actually I did know that. And I have read Javadocs.
Then you already knew about the proleptic Gregorian calendar and that
the Java 'GregorianCalendar' accepts year 0.
2. This situation is recoverable since the user could easily correct
this if it was brought to his attention.
I'm just trying to lay out my reasoning on the basis of what you and
others have said on this subject to make sure I'm thinking this through
Well, I pointed out that "recoverable" was not relevant, as it is far
too loose a concept that can apply to both checked and unchecked
exceptions, and therefore does not distinguish when to use one or the
I don't see what being "recoverable" has to do with anything. What
exactly do you mean by "recoverable" anyway?
One of the criteria for whether to make something a checked or unchecked
exception is whether an error is "recoverable", meaning (loosely) that
No, it isn't.
there is some prospect that the error can be eliminated with a bit of
human intervention. In this case, that human intervention would be
displaying a message to the user saying that the year 0000 is not valid
and please change it to a year that actually existed.
That reasoning applies equally well to checked or unchecked
3. IllegalArgumentException should be put in the throws clause of the
As I have said a couple of times already in this thread, and surely
you have read, because it accomplishes nothing. It does not add to
the documentation, it does not become part of the method signature, it
does not require callers to catch the exception, and it's a waste of
time and effort. The 'throws' clause is designed for and only useful
with checked exceptions.
Instead, as you wrote:
4. The Javadoc @throws (or @exception) should list
If GregorianCalendar is going to interpret the year 0 as the 1 BC without
my telling it to, I'm not sure I want to use GregorianCalendar....
But that is correct behavior, by ISO standard 8601. You really need
to study up on calendars, particularly the Gregorian calendar. May I
suggest careful study of
Sometimes people, and APIs, do the right thing even if you don't tell
them to. Furthermore, it is not your job to tell the standard API
what to do, but the standard API's job to tell you what it actually
does. As long as it works as documented, then you have no legitimate
Anyway, the year 0 is not really important here. I'm just trying to
construct an example of what I consider a "recoverable" (for want of a
better word) error so that I can see if I am understanding the use of
checked and unchecked exceptions yet.
"Recoverable" is an awful, terrible, vague, useless, unworthy and
ridiculous criterion for choosing between the two. Instead, consider
- RuntimeException for programmer error, checked exception for
environmental error, or
- RuntimeException to let a caller slide without a 'catch' clause,
checked exception to force the 'catch'.
Whatever criterion you use, it's going to be a matter of style. There
are entire APIs out there that refuse to throw checked exceptions by
dint of the API writers' philosophy, others that go hog-wild with
them. It's up to the API writer what they choose to impose.