MATH-566
Changed all exception classes to use the new "ExceptionContext". git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1101029 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ec6dbad43a
commit
c7f092e022
|
@ -34,7 +34,7 @@ public class ConvergenceException extends MathIllegalStateException {
|
|||
* Construct the exception.
|
||||
*/
|
||||
public ConvergenceException() {
|
||||
addMessage(LocalizedFormats.CONVERGENCE_FAILED);
|
||||
this(LocalizedFormats.CONVERGENCE_FAILED);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,6 +46,6 @@ public class ConvergenceException extends MathIllegalStateException {
|
|||
*/
|
||||
public ConvergenceException(Localizable pattern,
|
||||
Object ... args) {
|
||||
addMessage(pattern, args);
|
||||
getContext().addMessage(pattern, args);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,25 +18,30 @@ package org.apache.commons.math.exception;
|
|||
|
||||
import org.apache.commons.math.exception.util.Localizable;
|
||||
import org.apache.commons.math.exception.util.LocalizedFormats;
|
||||
import org.apache.commons.math.exception.util.ExceptionContext;
|
||||
import org.apache.commons.math.exception.util.ExceptionContextProvider;
|
||||
|
||||
/**
|
||||
* Base class for arithmetic exceptions.
|
||||
* It is used for all the exceptions that share the semantics of the standard
|
||||
* It is used for all the exceptions that have the semantics of the standard
|
||||
* {@link ArithmeticException}, but must also provide a localized
|
||||
* message.
|
||||
*
|
||||
* @since 3.0
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
public class MathArithmeticException extends MathRuntimeException {
|
||||
public class MathArithmeticException extends ArithmeticException
|
||||
implements ExceptionContextProvider {
|
||||
/** Serializable version Id. */
|
||||
private static final long serialVersionUID = -6024911025449780478L;
|
||||
/** Context. */
|
||||
private final ExceptionContext context = new ExceptionContext();
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public MathArithmeticException() {
|
||||
addMessage(LocalizedFormats.ARITHMETIC_EXCEPTION);
|
||||
context.addMessage(LocalizedFormats.ARITHMETIC_EXCEPTION);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -48,6 +53,23 @@ public class MathArithmeticException extends MathRuntimeException {
|
|||
*/
|
||||
public MathArithmeticException(Localizable pattern,
|
||||
Object ... args) {
|
||||
addMessage(pattern, args);
|
||||
context.addMessage(pattern, args);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public ExceptionContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return context.getMessage();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public String getLocalizedMessage() {
|
||||
return context.getLocalizedMessage();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ package org.apache.commons.math.exception;
|
|||
|
||||
import org.apache.commons.math.exception.util.Localizable;
|
||||
import org.apache.commons.math.exception.util.LocalizedFormats;
|
||||
import org.apache.commons.math.exception.util.ExceptionContext;
|
||||
import org.apache.commons.math.exception.util.ExceptionContextProvider;
|
||||
|
||||
/**
|
||||
* Base class for all exceptions that signal a mismatch between the
|
||||
|
@ -26,9 +28,12 @@ import org.apache.commons.math.exception.util.LocalizedFormats;
|
|||
* @since 2.2
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
public class MathIllegalStateException extends MathRuntimeException {
|
||||
public class MathIllegalStateException extends IllegalStateException
|
||||
implements ExceptionContextProvider {
|
||||
/** Serializable version Id. */
|
||||
private static final long serialVersionUID = -6024911025449780478L;
|
||||
/** Context. */
|
||||
private final ExceptionContext context = new ExceptionContext();
|
||||
|
||||
/**
|
||||
* Simple constructor.
|
||||
|
@ -38,7 +43,7 @@ public class MathIllegalStateException extends MathRuntimeException {
|
|||
*/
|
||||
public MathIllegalStateException(Localizable pattern,
|
||||
Object ... args) {
|
||||
addMessage(pattern, args);
|
||||
context.addMessage(pattern, args);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,13 +57,30 @@ public class MathIllegalStateException extends MathRuntimeException {
|
|||
Localizable pattern,
|
||||
Object ... args) {
|
||||
super(cause);
|
||||
addMessage(pattern, args);
|
||||
context.addMessage(pattern, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
public MathIllegalStateException() {
|
||||
addMessage(LocalizedFormats.ILLEGAL_STATE);
|
||||
this(LocalizedFormats.ILLEGAL_STATE);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public ExceptionContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return context.getMessage();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public String getLocalizedMessage() {
|
||||
return context.getLocalizedMessage();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public class MathInternalError extends MathIllegalStateException {
|
|||
* Simple constructor.
|
||||
*/
|
||||
public MathInternalError() {
|
||||
addMessage(LocalizedFormats.INTERNAL_ERROR, REPORT_URL);
|
||||
getContext().addMessage(LocalizedFormats.INTERNAL_ERROR, REPORT_URL);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,5 +44,4 @@ public class MathInternalError extends MathIllegalStateException {
|
|||
public MathInternalError(final Throwable cause) {
|
||||
super(cause, LocalizedFormats.INTERNAL_ERROR, REPORT_URL);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
package org.apache.commons.math.exception;
|
||||
|
||||
import org.apache.commons.math.exception.util.LocalizedFormats;
|
||||
import org.apache.commons.math.exception.util.ExceptionContext;
|
||||
import org.apache.commons.math.exception.util.ExceptionContextProvider;
|
||||
|
||||
/**
|
||||
* Class to signal parse failures.
|
||||
|
@ -24,7 +26,8 @@ import org.apache.commons.math.exception.util.LocalizedFormats;
|
|||
* @since 2.2
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
public class MathParseException extends MathRuntimeException {
|
||||
public class MathParseException extends MathIllegalStateException
|
||||
implements ExceptionContextProvider {
|
||||
/** Serializable version Id. */
|
||||
private static final long serialVersionUID = -6024911025449780478L;
|
||||
|
||||
|
@ -38,7 +41,7 @@ public class MathParseException extends MathRuntimeException {
|
|||
public MathParseException(String wrong,
|
||||
int position,
|
||||
Class<?> type) {
|
||||
addMessage(LocalizedFormats.CANNOT_PARSE_AS_TYPE,
|
||||
getContext().addMessage(LocalizedFormats.CANNOT_PARSE_AS_TYPE,
|
||||
wrong, Integer.valueOf(position), type.getName());
|
||||
}
|
||||
|
||||
|
@ -49,7 +52,7 @@ public class MathParseException extends MathRuntimeException {
|
|||
*/
|
||||
public MathParseException(String wrong,
|
||||
int position) {
|
||||
addMessage(LocalizedFormats.CANNOT_PARSE,
|
||||
getContext().addMessage(LocalizedFormats.CANNOT_PARSE,
|
||||
wrong, Integer.valueOf(position));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,19 +18,24 @@ package org.apache.commons.math.exception;
|
|||
|
||||
import org.apache.commons.math.exception.util.Localizable;
|
||||
import org.apache.commons.math.exception.util.LocalizedFormats;
|
||||
import org.apache.commons.math.exception.util.ExceptionContext;
|
||||
import org.apache.commons.math.exception.util.ExceptionContextProvider;
|
||||
|
||||
/**
|
||||
* Base class for all unsupported features.
|
||||
* It is used for all the exceptions that share the semantics of the standard
|
||||
* It is used for all the exceptions that have the semantics of the standard
|
||||
* {@link UnsupportedOperationException}, but must also provide a localized
|
||||
* message.
|
||||
*
|
||||
* @since 2.2
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
public class MathUnsupportedOperationException extends MathRuntimeException {
|
||||
public class MathUnsupportedOperationException extends UnsupportedOperationException
|
||||
implements ExceptionContextProvider {
|
||||
/** Serializable version Id. */
|
||||
private static final long serialVersionUID = -6024911025449780478L;
|
||||
/** Context. */
|
||||
private final ExceptionContext context = new ExceptionContext();
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
|
@ -45,6 +50,23 @@ public class MathUnsupportedOperationException extends MathRuntimeException {
|
|||
*/
|
||||
public MathUnsupportedOperationException(Localizable pattern,
|
||||
Object ... args) {
|
||||
addMessage(pattern, args);
|
||||
context.addMessage(pattern, args);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public ExceptionContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return context.getMessage();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public String getLocalizedMessage() {
|
||||
return context.getLocalizedMessage();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ package org.apache.commons.math.exception;
|
|||
|
||||
import org.apache.commons.math.exception.util.Localizable;
|
||||
import org.apache.commons.math.exception.util.LocalizedFormats;
|
||||
import org.apache.commons.math.exception.util.ExceptionContext;
|
||||
import org.apache.commons.math.exception.util.ExceptionContextProvider;
|
||||
|
||||
/**
|
||||
* This class is intended as a sort of communication channel between
|
||||
|
@ -28,15 +30,18 @@ import org.apache.commons.math.exception.util.LocalizedFormats;
|
|||
* @since 2.2
|
||||
* @version $Revision$ $Date$
|
||||
*/
|
||||
public class MathUserException extends MathRuntimeException {
|
||||
public class MathUserException extends RuntimeException
|
||||
implements ExceptionContextProvider {
|
||||
/** Serializable version Id. */
|
||||
private static final long serialVersionUID = -6024911025449780478L;
|
||||
/** Context. */
|
||||
private final ExceptionContext context = new ExceptionContext();
|
||||
|
||||
/**
|
||||
* Build an exception with a default message.
|
||||
*/
|
||||
public MathUserException() {
|
||||
addMessage(LocalizedFormats.USER_EXCEPTION);
|
||||
context.addMessage(LocalizedFormats.USER_EXCEPTION);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -45,7 +50,7 @@ public class MathUserException extends MathRuntimeException {
|
|||
*/
|
||||
public MathUserException(final Throwable cause) {
|
||||
super(cause);
|
||||
addMessage(LocalizedFormats.USER_EXCEPTION);
|
||||
context.addMessage(LocalizedFormats.USER_EXCEPTION);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,7 +61,7 @@ public class MathUserException extends MathRuntimeException {
|
|||
*/
|
||||
public MathUserException(final Localizable pattern,
|
||||
final Object ... arguments) {
|
||||
addMessage(pattern, arguments);
|
||||
context.addMessage(pattern, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -70,6 +75,23 @@ public class MathUserException extends MathRuntimeException {
|
|||
final Localizable pattern,
|
||||
final Object ... arguments) {
|
||||
super(cause);
|
||||
addMessage(pattern, arguments);
|
||||
context.addMessage(pattern, arguments);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public ExceptionContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return context.getMessage();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public String getLocalizedMessage() {
|
||||
return context.getLocalizedMessage();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,8 +39,7 @@ public class MaxCountExceededException extends MathIllegalStateException {
|
|||
* @param max Maximum.
|
||||
*/
|
||||
public MaxCountExceededException(Number max) {
|
||||
super(LocalizedFormats.MAX_COUNT_EXCEEDED, max);
|
||||
this.max = max;
|
||||
this(LocalizedFormats.MAX_COUNT_EXCEEDED, max);
|
||||
}
|
||||
/**
|
||||
* Construct the exception with a specific context.
|
||||
|
@ -52,8 +51,8 @@ public class MaxCountExceededException extends MathIllegalStateException {
|
|||
public MaxCountExceededException(Localizable specific,
|
||||
Number max,
|
||||
Object ... args) {
|
||||
this(max);
|
||||
addMessage(specific, max, args);
|
||||
getContext().addMessage(specific, max, args);
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -34,6 +34,7 @@ public class TooManyEvaluationsException extends MaxCountExceededException {
|
|||
* @param max Maximum number of evaluations.
|
||||
*/
|
||||
public TooManyEvaluationsException(Number max) {
|
||||
super(LocalizedFormats.EVALUATIONS, max);
|
||||
super(max);
|
||||
getContext().addMessage(LocalizedFormats.EVALUATIONS);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,6 +52,13 @@ 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="erans" type="add" issue="MATH-566">
|
||||
Created an "ExceptionContext" class: It provides the customization feature of
|
||||
"MathRuntimeException" without imposing a singly rooted hierarchy of the Comons
|
||||
Math exceptions.
|
||||
Thus, those exceptions now inherit from their Java standard counterparts (e.g.
|
||||
"MathIllegalArgumentException" inherits from "IllegalArgumentException").
|
||||
</action>
|
||||
<action dev="luc" type="add" issue="MATH-567" due-to="Michel">
|
||||
Fixed conversion problems to/from 0 in Decimal Floating Point (Dfp) class.
|
||||
</action>
|
||||
|
|
Loading…
Reference in New Issue