commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bruno P. Kinoshita (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (MATH-1408) Do not use exceptions for control flow
Date Thu, 06 Apr 2017 02:28:41 GMT

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

Bruno P. Kinoshita commented on MATH-1408:
------------------------------------------

[~erans] breaks binary compatibility, but gives an example of a generified Frequency class
https://github.com/apache/commons-math/compare/master...kinow:MATH-1408-generic-frequency?expand=1

This removes the ClassCastException, as well as suppress warnings annotations that we had.
Users wouldn't be able to use Frequency for three different types (i.e. int, long, char).
Instead, they would either have to maintain multiple Frequency objects, or convert everything
to, say, Long.

> Do not use exceptions for control flow
> --------------------------------------
>
>                 Key: MATH-1408
>                 URL: https://issues.apache.org/jira/browse/MATH-1408
>             Project: Commons Math
>          Issue Type: Task
>            Reporter: Gilles
>            Priority: Minor
>              Labels: control, exception, flow
>             Fix For: 4.0
>
>
> There are several occurrences where exception is used to control flow.
> Code such as
> {noformat}
> try  {
>  // block A
> } catch (ClassCastException e) {
>  // block B
> }
> {noformat}
> where "block A" is trying to cast an object "o" to "SomeClass", should be changed to
> {noformat}
> if (o instanceof SomeClass)  {
>  // block A
> } else {
>  // block B
> }
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message