Replaced checked ConvergenceException with an unchecked version.

JIRA: MATH-487

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1177986 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2011-10-01 14:16:50 +00:00
parent cbb10701a7
commit 036ba4efec
10 changed files with 16 additions and 146 deletions

View File

@ -1,71 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math;
import org.apache.commons.math.exception.util.Localizable;
import org.apache.commons.math.exception.util.LocalizedFormats;
/**
* Error thrown when a numerical computation can not be performed because the
* numerical result failed to converge to a finite value.
*
* @version $Id$
*/
public class ConvergenceException extends MathException {
/** Serializable version identifier */
private static final long serialVersionUID = -1111352570797662604L;
/**
* Default constructor.
*/
public ConvergenceException() {
super(LocalizedFormats.CONVERGENCE_FAILED);
}
/**
* Constructs an exception with specified formatted detail message.
* Message formatting is delegated to {@link java.text.MessageFormat}.
* @param pattern format specifier
* @param arguments format arguments
* @since 2.2
*/
public ConvergenceException(Localizable pattern, Object ... arguments) {
super(pattern, arguments);
}
/**
* Create an exception with a given root cause.
* @param cause the exception or error that caused this exception to be thrown
*/
public ConvergenceException(Throwable cause) {
super(cause);
}
/**
* Constructs an exception with specified formatted detail message and root cause.
* Message formatting is delegated to {@link java.text.MessageFormat}.
* @param cause the exception or error that caused this exception to be thrown
* @param pattern format specifier
* @param arguments format arguments
* @since 2.2
*/
public ConvergenceException(Throwable cause, Localizable pattern, Object ... arguments) {
super(cause, pattern, arguments);
}
}

View File

@ -17,7 +17,7 @@
package org.apache.commons.math.fraction;
import org.apache.commons.math.ConvergenceException;
import org.apache.commons.math.exception.ConvergenceException;
import org.apache.commons.math.exception.util.LocalizedFormats;
/**

View File

@ -23,7 +23,7 @@ import java.text.ParseException;
import java.text.ParsePosition;
import java.util.Locale;
import org.apache.commons.math.ConvergenceException;
import org.apache.commons.math.exception.ConvergenceException;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.exception.util.LocalizedFormats;

View File

@ -17,7 +17,7 @@
package org.apache.commons.math.optimization;
import org.apache.commons.math.ConvergenceException;
import org.apache.commons.math.exception.ConvergenceException;
import org.apache.commons.math.exception.util.Localizable;
/**
@ -44,12 +44,4 @@ public class OptimizationException extends ConvergenceException {
super(specifier, parts);
}
/**
* Create an exception with a given root cause.
* @param cause the exception or error that caused this exception to be thrown
*/
public OptimizationException(Throwable cause) {
super(cause);
}
}

View File

@ -90,13 +90,13 @@ public abstract class AbstractLinearOptimizer implements LinearOptimizer {
}
/** Increment the iterations counter by 1.
* @exception OptimizationException if the maximal number
* @exception MaxCountExceededException if the maximal number
* of iterations is exceeded
*/
protected void incrementIterationsCounter()
throws OptimizationException {
throws MaxCountExceededException {
if (++iterations > maxIterations) {
throw new OptimizationException(new MaxCountExceededException(maxIterations));
throw new MaxCountExceededException(maxIterations);
}
}

View File

@ -52,6 +52,9 @@ The <action> type attribute can be add,update,fix,remove.
If the output is not quite correct, check for invisible trailing spaces!
-->
<release version="3.0" date="TBD" description="TBD">
<action dev="luc" type="fix" issue="MATH-487" >
The checked ConvergenceException has been replaced by an unchecked ConvergenceException.
</action>
<action dev="luc" type="fix" issue="MATH-381" due-to="Pascal Parraud">
ODE step interpolation with Jacobians is now fully merged with
classical step interpolation.

View File

@ -1,47 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.math;
import java.util.Locale;
import org.junit.Assert;
import org.junit.Test;
/**
* @version $Id$
*/
public class ConvergenceExceptionTest {
@Test
public void testConstructor(){
ConvergenceException ex = new ConvergenceException();
Assert.assertNull(ex.getCause());
Assert.assertNotNull(ex.getMessage());
Assert.assertNotNull(ex.getMessage(Locale.FRENCH));
Assert.assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
}
@Test
public void testConstructorCause(){
String inMsg = "inner message";
Exception cause = new Exception(inMsg);
ConvergenceException ex = new ConvergenceException(cause);
Assert.assertEquals(cause, ex.getCause());
}
}

View File

@ -18,7 +18,6 @@ package org.apache.commons.math.analysis.integration;
import java.util.Random;
import org.apache.commons.math.ConvergenceException;
import org.apache.commons.math.MathException;
import org.apache.commons.math.analysis.QuinticFunction;
import org.apache.commons.math.analysis.SinFunction;
@ -76,8 +75,7 @@ public class LegendreGaussIntegratorTest {
}
@Test
public void testExactIntegration()
throws ConvergenceException {
public void testExactIntegration() {
Random random = new Random(86343623467878363l);
for (int n = 2; n < 6; ++n) {
LegendreGaussIntegrator integrator =
@ -105,7 +103,7 @@ public class LegendreGaussIntegratorTest {
}
@Test
public void testIssue464() throws ConvergenceException {
public void testIssue464() {
final double value = 0.2;
UnivariateRealFunction f = new UnivariateRealFunction() {
public double value(double x) {

View File

@ -19,8 +19,8 @@ package org.apache.commons.math.fraction;
import java.math.BigDecimal;
import java.math.BigInteger;
import org.apache.commons.math.ConvergenceException;
import org.apache.commons.math.TestUtils;
import org.apache.commons.math.exception.ConvergenceException;
import org.apache.commons.math.exception.NullArgumentException;
import org.apache.commons.math.util.FastMath;
import org.junit.Assert;

View File

@ -16,7 +16,7 @@
*/
package org.apache.commons.math.fraction;
import org.apache.commons.math.ConvergenceException;
import org.apache.commons.math.exception.ConvergenceException;
import org.apache.commons.math.exception.MathIllegalArgumentException;
import org.apache.commons.math.exception.MathArithmeticException;
import org.apache.commons.math.TestUtils;
@ -65,15 +65,10 @@ public class FractionTest {
assertFraction(15, 1, new Fraction(15.0000000000001));
}
@Test
@Test(expected=ConvergenceException.class)
public void testGoldenRatio() {
try {
// the golden ratio is notoriously a difficult number for continuous fraction
new Fraction((1 + FastMath.sqrt(5)) / 2, 1.0e-12, 25);
Assert.fail("an exception should have been thrown");
} catch (ConvergenceException ce) {
// expected behavior
}
// the golden ratio is notoriously a difficult number for continuous fraction
new Fraction((1 + FastMath.sqrt(5)) / 2, 1.0e-12, 25);
}
// MATH-179