improved error messages

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/branches/MATH_2_0@712430 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2008-11-08 20:42:55 +00:00
parent d00137cca7
commit 6b07dd2122
13 changed files with 106 additions and 25 deletions

View File

@ -174,6 +174,8 @@ public class MessagesResources_fr
// org.apache.commons.math.linear.EigenDecompositionImpl
{ "negative element on decomposed tridiagonal of {0}x{1} matrix",
"\u00e9l\u00e9ment n\u00e9gatif dans la d\u00e9composition tri-diagonale d''une matrice {0}x{1}" },
{ "internal error: please file a bug report at https://issues.apache.org/jira/browse/MATH",
"erreur interne : veuillez enregistrer un rapport de bogue sur https://issues.apache.org/jira/browse/MATH" },
// org.apache.commons.math.linear.NonSquareMatrixException
{ "a {0}x{1} matrix was provided instead of a square matrix",
@ -256,11 +258,51 @@ public class MessagesResources_fr
"norme nulle pour un axe de rotation" },
// org.apache.commons.math.geometry.Vector3D
// org.apache.commons.math.linear.RealVectorImpl
// org.apache.commons.math.linear.RealVectorImpl
{ "cannot normalize a zero norm vector",
"impossible de normer un vecteur de norme nulle" },
{ "zero norm",
"norme nulle" }
"norme nulle" },
// org.apache.commons.math.analysis.UnivariateRealIntegratorImpl
// org.apache.commons.math.analysis.UnivariateRealSolverImpl
{ "no result available",
"aucun r\u00e9sultat n''est disponible" },
// org.apache.commons.math.linear.BigMatrixImpl
{ "first {0} rows are not initialized yet",
"les {0} premi\u00e8res lignes ne sont pas encore initialis\u00e9es" },
{ "first {0} columns are not initialized yet",
"les {0} premi\u00e8res colonnes ne sont pas encore initialis\u00e9es" },
// org.apache.commons.math.linear.EigenDecompositionImpl
// org.apache.commons.math.linear.LUDecompositionImpl
// org.apache.commons.math.linear.QRDecompositionImpl
// org.apache.commons.math.linear.SingularValueDecompositionImpl
{ "no matrix have been decomposed yet",
"aucune matrice n''a encore \u00e9t\u00e9 d\u00e9compos\u00e9e" },
// org.apache.commons.math.random.EmpiricalDistributionImpl
{ "distribution not loaded",
"aucune distribution n''a \u00e9t\u00e9 charg\u00e9e" },
// org.apache.commons.math.random.ValueServer
{ "unknown mode {0}, known modes: {1} ({2}), {3} ({4}), {5} ({6}), {7} ({8}), {9} ({10}) and {11} ({12})",
"mode {0} inconnu, modes connus : {1} ({2}), {3} ({4}), {5} ({6}), {7} ({8}), {9} ({10}) et {11} ({12})" },
{ "digest not initialized",
"mod\u00e8le empirique non initialis\u00e9" },
// org.apache.commons.math.stat.descriptive.moment.GeometricMean
// org.apache.commons.math.stat.descriptive.MultivariateSummaryStatistics
// org.apache.commons.math.stat.descriptive.SummaryStatistics
{ "{0} values have been added before statistic is configured",
"{0} valeurs ont \u00e9t\u00e9 ajout\u00e9es avant que la statistique ne soit configur\u00e9e" },
// org.apache.commons.math.stat.descriptive.moment.Kurtosis
{ "statistics constructed from external moments cannot be incremented",
"les statistiques bas\u00e9es sur des moments externes ne peuvent pas \u00eatre incr\u00e9ment\u00e9es" },
{ "statistics constructed from external moments cannot be cleared",
"les statistiques bas\u00e9es sur des moments externes ne peuvent pas \u00eatre remises \u00e0 z\u00e9ro" }
};

View File

@ -18,6 +18,8 @@ package org.apache.commons.math.analysis;
import java.io.Serializable;
import org.apache.commons.math.MathRuntimeException;
/**
* Provide a default implementation for several generic functions.
*
@ -99,7 +101,7 @@ public abstract class UnivariateRealIntegratorImpl implements
if (resultComputed) {
return result;
} else {
throw new IllegalStateException("No result available.");
throw MathRuntimeException.createIllegalStateException("no result available", null);
}
}
@ -113,7 +115,7 @@ public abstract class UnivariateRealIntegratorImpl implements
if (resultComputed) {
return iterationCount;
} else {
throw new IllegalStateException("No result available.");
throw MathRuntimeException.createIllegalStateException("no result available", null);
}
}

View File

@ -20,6 +20,7 @@ package org.apache.commons.math.analysis;
import java.io.Serializable;
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.MathRuntimeException;
/**
* Provide a default implementation for several functions useful to generic
@ -111,7 +112,7 @@ public abstract class UnivariateRealSolverImpl implements UnivariateRealSolver,
if (resultComputed) {
return result;
} else {
throw new IllegalStateException("No result available");
throw MathRuntimeException.createIllegalStateException("no result available", null);
}
}
@ -126,7 +127,7 @@ public abstract class UnivariateRealSolverImpl implements UnivariateRealSolver,
if (resultComputed) {
return iterationCount;
} else {
throw new IllegalStateException("No result available");
throw MathRuntimeException.createIllegalStateException("no result available", null);
}
}

View File

@ -19,6 +19,8 @@ package org.apache.commons.math.linear;
import java.io.Serializable;
import java.math.BigDecimal;
import org.apache.commons.math.MathRuntimeException;
/**
* Implementation of {@link BigMatrix} using a BigDecimal[][] array to store entries
* and <a href="http://www.math.gatech.edu/~bourbaki/math2601/Web-notes/2num.pdf">
@ -697,8 +699,13 @@ public class BigMatrixImpl implements BigMatrix, Serializable {
}
if (data == null) {
if ((row > 0) || (column > 0)) {
throw new IllegalStateException("matrix must be initialized to perform this method");
if (row > 0) {
throw MathRuntimeException.createIllegalStateException("first {0} rows are not initialized yet",
new Object[] { row });
}
if (column > 0) {
throw MathRuntimeException.createIllegalStateException("first {0} columns are not initialized yet",
new Object[] { column });
}
data = new BigDecimal[nRows][nCols];
System.arraycopy(subMatrix, 0, data, 0, subMatrix.length);

View File

@ -17,6 +17,8 @@
package org.apache.commons.math.linear;
import org.apache.commons.math.MathRuntimeException;
/**
* Calculates the LUP-decomposition of a square matrix.
* <p>The LUP-decomposition of a matrix A consists of three matrices
@ -431,7 +433,7 @@ public class LUDecompositionImpl implements LUDecomposition {
private void checkDecomposed()
throws IllegalStateException {
if (lu == null) {
throw new IllegalStateException("no matrix have been decomposed yet");
throw MathRuntimeException.createIllegalStateException("no matrix have been decomposed yet", null);
}
}

View File

@ -17,6 +17,8 @@
package org.apache.commons.math.linear;
import org.apache.commons.math.MathRuntimeException;
/**
* Calculates the QR-decomposition of a matrix.
* <p>The QR-decomposition of a matrix A consists of two matrices Q and R
@ -443,7 +445,7 @@ public class QRDecompositionImpl implements QRDecomposition {
private void checkDecomposed()
throws IllegalStateException {
if (qrt == null) {
throw new IllegalStateException("no matrix have been decomposed yet");
throw MathRuntimeException.createIllegalStateException("no matrix have been decomposed yet", null);
}
}

View File

@ -18,6 +18,8 @@
package org.apache.commons.math.linear;
import java.io.Serializable;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.util.MathUtils;
@ -488,8 +490,13 @@ public class RealMatrixImpl implements RealMatrix, Serializable {
}
if (data == null) {
if ((row > 0) || (column > 0)) {
throw new IllegalStateException("matrix must be initialized to perform this method");
if (row > 0) {
throw MathRuntimeException.createIllegalStateException("first {0} rows are not initialized yet",
new Object[] { row });
}
if (column > 0) {
throw MathRuntimeException.createIllegalStateException("first {0} columns are not initialized yet",
new Object[] { column });
}
data = new double[nRows][nCols];
System.arraycopy(subMatrix, 0, data, 0, subMatrix.length);

View File

@ -413,7 +413,8 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib
public double getNextValue() throws IllegalStateException {
if (!loaded) {
throw new IllegalStateException("distribution not loaded");
throw MathRuntimeException.createIllegalStateException("distribution not loaded",
null);
}
// Start with a uniformly distributed random number in (0,1)

View File

@ -106,8 +106,18 @@ public class ValueServer {
case EXPONENTIAL_MODE: return getNextExponential();
case GAUSSIAN_MODE: return getNextGaussian();
case CONSTANT_MODE: return mu;
default: throw new IllegalStateException
("Bad mode: " + mode);
default: throw MathRuntimeException.createIllegalStateException("unknown mode {0}, known modes: " +
"{1} ({2}), {3} ({4}), {5} ({6}), " +
"{7} ({8}), {9} ({10}) and {11} ({12})",
new Object[] {
mode,
"DIGEST_MODE", DIGEST_MODE,
"REPLAY_MODE", REPLAY_MODE,
"UNIFORM_MODE", UNIFORM_MODE,
"EXPONENTIAL_MODE", EXPONENTIAL_MODE,
"GAUSSIAN_MODE", GAUSSIAN_MODE,
"CONSTANT_MODE", CONSTANT_MODE
});
}
}
@ -296,7 +306,7 @@ public class ValueServer {
private double getNextDigest() {
if ((empiricalDistribution == null) ||
(empiricalDistribution.getBinStats().size() == 0)) {
throw new IllegalStateException("Digest not initialized");
throw MathRuntimeException.createIllegalStateException("digest not initialized", null);
}
return empiricalDistribution.getNextValue();
}

View File

@ -20,6 +20,7 @@ import java.io.Serializable;
import java.util.Arrays;
import org.apache.commons.math.DimensionMismatchException;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.stat.descriptive.moment.GeometricMean;
import org.apache.commons.math.stat.descriptive.moment.Mean;
@ -609,8 +610,8 @@ public class MultivariateSummaryStatistics
*/
private void checkEmpty() {
if (n > 0) {
throw new IllegalStateException(
"Implementations must be configured before values are added.");
throw MathRuntimeException.createIllegalStateException("{0} values have been added before statistic is configured",
new Object[] { n });
}
}

View File

@ -18,6 +18,7 @@ package org.apache.commons.math.stat.descriptive;
import java.io.Serializable;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.stat.descriptive.moment.GeometricMean;
import org.apache.commons.math.stat.descriptive.moment.Mean;
import org.apache.commons.math.stat.descriptive.moment.SecondMoment;
@ -599,7 +600,8 @@ public class SummaryStatistics implements StatisticalSummary, Serializable {
*/
private void checkEmpty() {
if (n > 0) {
throw new IllegalStateException("Implementations must be configured before values are added.");
throw MathRuntimeException.createIllegalStateException("{0} values have been added before statistic is configured",
new Object[] { n });
}
}

View File

@ -16,6 +16,7 @@
*/
package org.apache.commons.math.stat.descriptive.moment;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic;
import org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic;
import org.apache.commons.math.stat.descriptive.summary.SumOfLogs;
@ -152,8 +153,8 @@ public class GeometricMean extends AbstractStorelessUnivariateStatistic {
*/
private void checkEmpty() {
if (getN() > 0) {
throw new IllegalStateException(
"Implementation must be configured before values are added.");
throw MathRuntimeException.createIllegalStateException("{0} values have been added before statistic is configured",
new Object[] { getN() });
}
}

View File

@ -16,6 +16,7 @@
*/
package org.apache.commons.math.stat.descriptive.moment;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic;
/**
@ -79,8 +80,9 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic {
if (incMoment) {
moment.increment(d);
} else {
throw new IllegalStateException
("Statistics constructed from external moments cannot be incremented");
throw MathRuntimeException.createIllegalStateException("statistics constructed from external " +
"moments cannot be incremented",
null);
}
}
@ -111,8 +113,9 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic {
if (incMoment) {
moment.clear();
} else {
throw new IllegalStateException
("Statistics constructed from external moments cannot be cleared");
throw MathRuntimeException.createIllegalStateException("statistics constructed from external " +
"moments cannot be cleared",
null);
}
}