commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Steitz (JIRA)" <j...@apache.org>
Subject [jira] Commented: (MATH-195) Inconsistencies in the Exception hierarchy
Date Sun, 09 Mar 2008 15:31:46 GMT

    [ https://issues.apache.org/jira/browse/MATH-195?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12576784#action_12576784
] 

Phil Steitz commented on MATH-195:
----------------------------------

Could be though we had it wrong in [math] to begin with.  IIRC, early on there were discussions
about cluttering client code with catches for checked exceptions due to bad arguments that
amounted to violations of the API contract - i.e., violations of stated preconditions or "nonsensical"
arguments.  For example, trying to get the (not generalized) inverse of a matrix that is not
square.  We agreed that it was better to make these RTEs and in many cases what is thrown
is IllegalArgumentException.

We knew from the beginning that the exceptions hierarchy in the initial releases of [math]
was weak and that we would have to refactor / rethink it if the little library was to grow.
 Well, now it has grown, largely thanks to the Luc's Mantissa contribution and I think it
is fair for us to rethink.  I think we should do that now and I would be OK with any of  
a) leaving "legacy" unchecked exceptions as is for backward compatabiltiy but adopting the
Mantissa guidlines above moving forward
b) merging the two sets of guidelines by defining a category of "truly illegal argument" cases
where we throw sublcasses of IAE, but keeping the Mantissa guidelines for non-obvious violations
of preconditions.  Perhaps an example of that would be NotPositiveDefiniteMatrixException.
c) make all exceptions associated with arguments subclass IAE
d) deprecate "legacy" methods throwing IAE and replace with methods advertising checked exceptions
(this one might be painful)

The least traumatic is b) and I think that may be possible to precise, so that has my vote.
 Could be a) and b) amount to the same thing.

> Inconsistencies in the Exception hierarchy
> ------------------------------------------
>
>                 Key: MATH-195
>                 URL: https://issues.apache.org/jira/browse/MATH-195
>             Project: Commons Math
>          Issue Type: Improvement
>    Affects Versions: 1.1, 1.2, 2.0, Nightly Builds
>            Reporter: Thomas Chust
>            Assignee: Brent Worden
>            Priority: Minor
>             Fix For: 2.0
>
>   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.


Mime
View raw message