allow chained IOExceptions even before Java 6
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/branches/MATH_2_0@712187 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
448759e46e
commit
d00137cca7
|
@ -17,6 +17,7 @@
|
||||||
package org.apache.commons.math;
|
package org.apache.commons.math;
|
||||||
|
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
|
@ -248,6 +249,22 @@ public class MathRuntimeException extends RuntimeException {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new <code>IOException</code> with specified nested
|
||||||
|
* <code>Throwable</code> root cause.
|
||||||
|
* <p>This factory method allows chaining of other exceptions within an
|
||||||
|
* <code>IOException</code> even for Java 5. The constructor for
|
||||||
|
* <code>IOException</code> with a cause parameter was introduced only
|
||||||
|
* with Java 6.</p>
|
||||||
|
* @param rootCause the exception or error that caused this exception
|
||||||
|
* to be thrown.
|
||||||
|
*/
|
||||||
|
public static IOException createIOException(final Throwable rootCause) {
|
||||||
|
IOException ioe = new IOException(rootCause.getLocalizedMessage());
|
||||||
|
ioe.initCause(rootCause);
|
||||||
|
return ioe;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new <code>IllegalArgumentException</code> with specified formatted detail message.
|
* Constructs a new <code>IllegalArgumentException</code> with specified formatted detail message.
|
||||||
* Message formatting is delegated to {@link java.text.MessageFormat}.
|
* Message formatting is delegated to {@link java.text.MessageFormat}.
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.io.IOException;
|
||||||
import java.io.ObjectInput;
|
import java.io.ObjectInput;
|
||||||
import java.io.ObjectOutput;
|
import java.io.ObjectOutput;
|
||||||
|
|
||||||
|
import org.apache.commons.math.MathRuntimeException;
|
||||||
import org.apache.commons.math.ode.DerivativeException;
|
import org.apache.commons.math.ode.DerivativeException;
|
||||||
import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
|
import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
|
||||||
import org.apache.commons.math.ode.sampling.StepInterpolator;
|
import org.apache.commons.math.ode.sampling.StepInterpolator;
|
||||||
|
@ -250,7 +251,7 @@ class DormandPrince853StepInterpolator
|
||||||
// save the local attributes
|
// save the local attributes
|
||||||
finalizeStep();
|
finalizeStep();
|
||||||
} catch (DerivativeException e) {
|
} catch (DerivativeException e) {
|
||||||
throw new IOException(e.getMessage());
|
throw MathRuntimeException.createIOException(e);
|
||||||
}
|
}
|
||||||
out.writeInt(currentState.length);
|
out.writeInt(currentState.length);
|
||||||
for (int i = 0; i < currentState.length; ++i) {
|
for (int i = 0; i < currentState.length; ++i) {
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.io.ObjectInput;
|
||||||
import java.io.ObjectOutput;
|
import java.io.ObjectOutput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.commons.math.MathRuntimeException;
|
||||||
import org.apache.commons.math.ode.DerivativeException;
|
import org.apache.commons.math.ode.DerivativeException;
|
||||||
import org.apache.commons.math.ode.sampling.AbstractStepInterpolator;
|
import org.apache.commons.math.ode.sampling.AbstractStepInterpolator;
|
||||||
import org.apache.commons.math.ode.sampling.StepInterpolator;
|
import org.apache.commons.math.ode.sampling.StepInterpolator;
|
||||||
|
@ -392,7 +393,7 @@ class GraggBulirschStoerStepInterpolator
|
||||||
// we can now set the interpolated time and state
|
// we can now set the interpolated time and state
|
||||||
setInterpolatedTime(t);
|
setInterpolatedTime(t);
|
||||||
} catch (DerivativeException e) {
|
} catch (DerivativeException e) {
|
||||||
throw new IOException(e.getMessage());
|
throw MathRuntimeException.createIOException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.io.IOException;
|
||||||
import java.io.ObjectInput;
|
import java.io.ObjectInput;
|
||||||
import java.io.ObjectOutput;
|
import java.io.ObjectOutput;
|
||||||
|
|
||||||
|
import org.apache.commons.math.MathRuntimeException;
|
||||||
import org.apache.commons.math.ode.DerivativeException;
|
import org.apache.commons.math.ode.DerivativeException;
|
||||||
import org.apache.commons.math.ode.sampling.AbstractStepInterpolator;
|
import org.apache.commons.math.ode.sampling.AbstractStepInterpolator;
|
||||||
|
|
||||||
|
@ -157,7 +158,7 @@ abstract class MultistepStepInterpolator
|
||||||
// we can now set the interpolated time and state
|
// we can now set the interpolated time and state
|
||||||
setInterpolatedTime(t);
|
setInterpolatedTime(t);
|
||||||
} catch (DerivativeException e) {
|
} catch (DerivativeException e) {
|
||||||
throw new IOException(e.getMessage());
|
throw MathRuntimeException.createIOException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.io.ObjectInput;
|
||||||
import java.io.ObjectOutput;
|
import java.io.ObjectOutput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.commons.math.MathRuntimeException;
|
||||||
import org.apache.commons.math.ode.DerivativeException;
|
import org.apache.commons.math.ode.DerivativeException;
|
||||||
import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
|
import org.apache.commons.math.ode.FirstOrderDifferentialEquations;
|
||||||
import org.apache.commons.math.ode.sampling.AbstractStepInterpolator;
|
import org.apache.commons.math.ode.sampling.AbstractStepInterpolator;
|
||||||
|
@ -165,7 +166,7 @@ abstract class RungeKuttaStepInterpolator
|
||||||
// we can now set the interpolated time and state
|
// we can now set the interpolated time and state
|
||||||
setInterpolatedTime(t);
|
setInterpolatedTime(t);
|
||||||
} catch (DerivativeException e) {
|
} catch (DerivativeException e) {
|
||||||
throw new IOException(e.getMessage());
|
throw MathRuntimeException.createIOException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.io.ObjectInput;
|
||||||
import java.io.ObjectOutput;
|
import java.io.ObjectOutput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.commons.math.MathRuntimeException;
|
||||||
import org.apache.commons.math.ode.DerivativeException;
|
import org.apache.commons.math.ode.DerivativeException;
|
||||||
import org.apache.commons.math.ode.FirstOrderIntegrator;
|
import org.apache.commons.math.ode.FirstOrderIntegrator;
|
||||||
import org.apache.commons.math.ode.SecondOrderIntegrator;
|
import org.apache.commons.math.ode.SecondOrderIntegrator;
|
||||||
|
@ -369,7 +370,7 @@ public abstract class AbstractStepInterpolator
|
||||||
try {
|
try {
|
||||||
finalizeStep();
|
finalizeStep();
|
||||||
} catch (DerivativeException e) {
|
} catch (DerivativeException e) {
|
||||||
throw new IOException(e.getMessage());
|
throw MathRuntimeException.createIOException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.io.ObjectInput;
|
||||||
import java.io.ObjectOutput;
|
import java.io.ObjectOutput;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.commons.math.MathRuntimeException;
|
||||||
import org.apache.commons.math.ode.DerivativeException;
|
import org.apache.commons.math.ode.DerivativeException;
|
||||||
import org.apache.commons.math.ode.nonstiff.EmbeddedRungeKuttaIntegrator;
|
import org.apache.commons.math.ode.nonstiff.EmbeddedRungeKuttaIntegrator;
|
||||||
|
|
||||||
|
@ -119,7 +120,7 @@ public class DummyStepInterpolator
|
||||||
// we can now set the interpolated time and state
|
// we can now set the interpolated time and state
|
||||||
setInterpolatedTime(t);
|
setInterpolatedTime(t);
|
||||||
} catch (DerivativeException e) {
|
} catch (DerivativeException e) {
|
||||||
throw new IOException(e.getMessage());
|
throw MathRuntimeException.createIOException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,7 +136,7 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib
|
||||||
// don't wrap RuntimeExceptions
|
// don't wrap RuntimeExceptions
|
||||||
throw rte;
|
throw rte;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IOException(e.getMessage());
|
throw MathRuntimeException.createIOException(e);
|
||||||
}
|
}
|
||||||
if (sampleStats.getN() == 0) {
|
if (sampleStats.getN() == 0) {
|
||||||
throw MathRuntimeException.createEOFException("URL {0} contains no data",
|
throw MathRuntimeException.createEOFException("URL {0} contains no data",
|
||||||
|
@ -175,7 +175,7 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib
|
||||||
// don't wrap RuntimeExceptions
|
// don't wrap RuntimeExceptions
|
||||||
throw rte;
|
throw rte;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IOException(e.getMessage());
|
throw MathRuntimeException.createIOException(e);
|
||||||
}
|
}
|
||||||
in = new BufferedReader(new FileReader(file));
|
in = new BufferedReader(new FileReader(file));
|
||||||
fillBinStats(in);
|
fillBinStats(in);
|
||||||
|
@ -376,7 +376,7 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib
|
||||||
// don't wrap RuntimeExceptions
|
// don't wrap RuntimeExceptions
|
||||||
throw rte;
|
throw rte;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IOException(e.getMessage());
|
throw MathRuntimeException.createIOException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign upperBounds based on bin counts
|
// Assign upperBounds based on bin counts
|
||||||
|
|
|
@ -120,7 +120,7 @@ public class DummyStepInterpolatorTest
|
||||||
fail("an exception should have been thrown");
|
fail("an exception should have been thrown");
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
// expected behavior
|
// expected behavior
|
||||||
assertNull(ioe.getMessage());
|
assertEquals(0, ioe.getMessage().length());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("wrong exception caught");
|
fail("wrong exception caught");
|
||||||
}
|
}
|
||||||
|
@ -166,7 +166,7 @@ public class DummyStepInterpolatorTest
|
||||||
fail("an exception should have been thrown");
|
fail("an exception should have been thrown");
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
// expected behavior
|
// expected behavior
|
||||||
assertNull(ioe.getMessage());
|
assertEquals(0, ioe.getMessage().length());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
fail("wrong exception caught");
|
fail("wrong exception caught");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue