diff --git a/src/java/org/apache/commons/math/ode/ContinuousOutputModel.java b/src/java/org/apache/commons/math/ode/ContinuousOutputModel.java index b96c60cc6..b113ce123 100644 --- a/src/java/org/apache/commons/math/ode/ContinuousOutputModel.java +++ b/src/java/org/apache/commons/math/ode/ContinuousOutputModel.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.List; import java.io.Serializable; +import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.ode.nonstiff.AdaptiveStepsizeIntegrator; import org.apache.commons.math.ode.sampling.StepHandler; import org.apache.commons.math.ode.sampling.StepInterpolator; @@ -314,8 +315,7 @@ public class ContinuousOutputModel steps.get(index).setInterpolatedTime(time); } catch (DerivativeException de) { - throw new RuntimeException("unexpected DerivativeException caught: " + - de.getMessage()); + throw new MathRuntimeException("unexpected exception caught", new Object[0], de); } } diff --git a/src/java/org/apache/commons/math/optimization/DirectSearchOptimizer.java b/src/java/org/apache/commons/math/optimization/DirectSearchOptimizer.java index aedeab30a..622990ac7 100644 --- a/src/java/org/apache/commons/math/optimization/DirectSearchOptimizer.java +++ b/src/java/org/apache/commons/math/optimization/DirectSearchOptimizer.java @@ -22,6 +22,7 @@ import java.util.Comparator; import org.apache.commons.math.ConvergenceException; import org.apache.commons.math.DimensionMismatchException; +import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.linear.RealMatrix; import org.apache.commons.math.random.CorrelatedRandomVectorGenerator; import org.apache.commons.math.random.JDKRandomGenerator; @@ -269,7 +270,7 @@ public abstract class DirectSearchOptimizer { } catch (DimensionMismatchException dme) { // this should not happen - throw new RuntimeException("internal error"); + throw new MathRuntimeException("unexpected exception caught", new Object[0], dme); } } diff --git a/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java b/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java index 78a8e77af..2271babca 100644 --- a/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java +++ b/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java @@ -17,19 +17,20 @@ package org.apache.commons.math.random; -import java.io.EOFException; -import java.io.Serializable; import java.io.BufferedReader; -import java.io.FileReader; +import java.io.EOFException; import java.io.File; +import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; +import java.io.Serializable; import java.net.URL; import java.util.ArrayList; import java.util.List; -import org.apache.commons.math.stat.descriptive.SummaryStatistics; +import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.stat.descriptive.StatisticalSummary; +import org.apache.commons.math.stat.descriptive.SummaryStatistics; /** * Implements EmpiricalDistribution interface. This implementation @@ -110,7 +111,7 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib da.computeStats(); fillBinStats(in); } catch (Exception e) { - throw new RuntimeException(e.getMessage()); + throw new MathRuntimeException(e); } loaded = true; @@ -418,7 +419,7 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib } } } - throw new RuntimeException("No bin selected"); + throw new MathRuntimeException("no bin selected", new Object[0]); } /** diff --git a/src/test/org/apache/commons/math/random/EmpiricalDistributionTest.java b/src/test/org/apache/commons/math/random/EmpiricalDistributionTest.java index d2d9532b1..6ae16e9e1 100644 --- a/src/test/org/apache/commons/math/random/EmpiricalDistributionTest.java +++ b/src/test/org/apache/commons/math/random/EmpiricalDistributionTest.java @@ -26,6 +26,7 @@ import java.util.ArrayList; import junit.framework.Test; import junit.framework.TestSuite; +import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.RetryTestCase; import org.apache.commons.math.TestUtils; import org.apache.commons.math.stat.descriptive.SummaryStatistics; @@ -141,7 +142,11 @@ public final class EmpiricalDistributionTest extends RetryTestCase { empiricalDistribution.getNextValue(); empiricalDistribution2.getNextValue(); fail("Expecting IllegalStateException"); - } catch (IllegalStateException ex) {;} + } catch (IllegalStateException ex) { + // expected + } catch (Exception e) { + fail("wrong exception caught"); + } } /** @@ -190,9 +195,10 @@ public final class EmpiricalDistributionTest extends RetryTestCase { try { dist.load((double[]) null); fail("load((double[]) null) expected RuntimeException"); - } - catch (RuntimeException e) { + } catch (MathRuntimeException e) { // expected + } catch (Exception e) { + fail("wrong exception caught"); } } @@ -201,9 +207,10 @@ public final class EmpiricalDistributionTest extends RetryTestCase { try { dist.load((URL) null); fail("load((URL) null) expected NullPointerException"); - } - catch (NullPointerException e) { + } catch (NullPointerException e) { // expected + } catch (Exception e) { + fail("wrong exception caught"); } } @@ -212,9 +219,10 @@ public final class EmpiricalDistributionTest extends RetryTestCase { try { dist.load((File) null); fail("load((File) null) expected NullPointerException"); - } - catch (NullPointerException e) { + } catch (NullPointerException e) { // expected + } catch (Exception e) { + fail("wrong exception caught"); } } diff --git a/src/test/org/apache/commons/math/util/TestBean.java b/src/test/org/apache/commons/math/util/TestBean.java index 484b57550..3dc2c610a 100644 --- a/src/test/org/apache/commons/math/util/TestBean.java +++ b/src/test/org/apache/commons/math/util/TestBean.java @@ -17,6 +17,8 @@ package org.apache.commons.math.util; +import org.apache.commons.math.MathRuntimeException; + /** * @version $Revision$ $Date$ */ @@ -57,7 +59,7 @@ public class TestBean { * */ public Double getZ() { - throw new RuntimeException(); + throw new MathRuntimeException(); } /**