Re: Understanding Exceptions
Stanimir Stamenkov wrote:
And the assertion in this case would be the requirement of "SHA-256"
availability has failed. If it is a core application requirement
(probably documented), I think it deserves an Error. Don't you think
like that?
Lew wrote:
No, this is a condition for a checked exception.
An assertion represents confirmation of an algorithmic invariant.
Resource availability is not part of the algorithm but an environmental
condition for it.
Stanimir Stamenkov wrote:
Note, I don't unconditionally state the AssertionError is the best type
to use, but then some kind of Error subtype (see below).
Lew wrote:
The point of an 'Error' is that it "indicates serious problems that a
reasonable application should not try to catch."
<http://download.oracle.com/javase/6/docs/api/java/lang/Error.html>
A reasonable application certainly would try to catch a checked resource
exception and present recovery assistance through a log entry and, if
not headless, a display to the operator.
Stanimir Stamenkov wrote:
I've always wondered why JAXP, for example, has chosen to throw an Error
from DocumentBuilderFactory.newInstance() [1] and
SAXParserFactory.newInstance() [2]:
Throws:
FactoryConfigurationError - if the implementation is not
available or cannot be instantiated.
Isn't this a similar resource availability situation?
Apparently not in the minds of the JAXP API writers.
[1]
http://download.oracle.com/javase/6/docs/api/javax/xml/parsers/DocumentBuilderFactory.html#newInstance%28%29
[2]
http://download.oracle.com/javase/6/docs/api/javax/xml/parsers/SAXParserFactory.html#newInstance%28%29
Perhaps they see the lack of fundamental class libraries from the Java runtime
as more serious than a failure to plug in a particular encryption algorithm,
in that the former breaks the entire system and the latter only the situation
where you try to open a particular resource.
The 'NoSuchAlgorithm' situation is closer to a
<http://download.oracle.com/javase/6/docs/api/java/io/FileNotFoundException.html>
than to any kind of 'Error'.
--
Lew