commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Steitz (JIRA)" <>
Subject [jira] Commented: (MATH-195) Inconsistencies in the Exception hierarchy
Date Fri, 02 Jul 2010 02:50:50 GMT


Phil Steitz commented on MATH-195:

I disagree with the extreme view that all exceptions should be unchecked.  That is simply
bad Java programming, in my opinion.  I respectfully disagree with the opinions of Eckel et
al that checked exceptions should not exist.  I agree that exceptions should be unchecked
if a) they represent programming errors or b) there is (certainly) no reasonable recovery
(basically, I agree with Bloch and Sun).  But checked exceptions still make sense when a reasonable
request has been made by the caller and due to data or execution context the result is exceptional.
 A good [math] example is ConvergenceException and its subclasses.  We can argue about the
specificity of these classes and whether each is a suitable abstraction, but the abstraction
that ConvergenceException expresses is a classic use of checked exceptions.  I don't think
it is a "programming error" (nor do I think it reveals a [math] bug) to construct a BrentSolver
with a given absolute accuracy and maximum iterations and pass it a function and initial point
that results in a (checked) MaximumIterationsExceeded exception.  This situation may also
be recoverable - that is up to the caller.  Throwing an unchecked exception in that case would
be incorrect, IMO.  As a user of the class, I *like* having the try - catch with the advertised
exception in my code (what Luc calls self-documentiing) and seeing it in the javadoc.  I also
*like* having the compiler remind me if I omit it.   

> Inconsistencies in the Exception hierarchy
> ------------------------------------------
>                 Key: MATH-195
>                 URL:
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 1.1, 1.2, 2.0, Nightly Builds
>            Reporter: Thomas Chust
>            Assignee: Gilles
>            Priority: Minor
>             Fix For: 2.1
>   Original Estimate: 0.17h
>  Remaining Estimate: 0.17h
> I think there are some inconsistencies in the hierarchy of exceptions used by the Commons
Math library which could easily be fixed:
>   - org.apache.commons.math.linear.MatrixIndexException should really be a subclass of
>     java.lang.IndexOutOfBoundsException.
>   - Either org.apache.commons.math.linear.InvalidMatrixException should be checked or
>     org.apache.commons.math.random.NotPositiveDefiniteMatrixException and
>     org.apache.commons.math.geometry.NotARotationMatrixException should be unchecked,
but in any case the latter two
>     should be subclasses of the former. An unchecked InvalidMatrixException should probably
be a subclass of
>     java.lang.ArithmeticException while a checked InvalidMatrixException should be a
subclass of
>     org.apache.commons.math.MathException.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message