added new constructors to MathUserException to provide more control to user
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1035419 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0d52bf6394
commit
e5413fd483
|
@ -19,9 +19,9 @@ package org.apache.commons.math.exception;
|
|||
import java.util.Locale;
|
||||
|
||||
import org.apache.commons.math.exception.util.ArgUtils;
|
||||
import org.apache.commons.math.exception.util.MessageFactory;
|
||||
import org.apache.commons.math.exception.util.Localizable;
|
||||
import org.apache.commons.math.exception.util.LocalizedFormats;
|
||||
import org.apache.commons.math.exception.util.MessageFactory;
|
||||
|
||||
/**
|
||||
* This class is intended as a sort of communication channel between
|
||||
|
@ -36,40 +36,84 @@ public class MathUserException extends RuntimeException {
|
|||
/** Serializable version Id. */
|
||||
private static final long serialVersionUID = -6024911025449780478L;
|
||||
/**
|
||||
* Pattern used to build the message (problem description).
|
||||
* Pattern used to build the specific part of the message (problem description).
|
||||
*/
|
||||
private final Localizable pattern;
|
||||
private final Localizable specific;
|
||||
/**
|
||||
* Pattern used to build the general part of the message (problem description).
|
||||
*/
|
||||
private final Localizable general;
|
||||
/**
|
||||
* Arguments used to build the message.
|
||||
*/
|
||||
private final Object[] arguments;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
* Build an exception with a default message.
|
||||
*/
|
||||
public MathUserException() {
|
||||
this(null);
|
||||
this((Throwable) null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param cause Cause of the error.
|
||||
* @param args Arguments.
|
||||
* Build an exception with a default message.
|
||||
* @param cause Cause of the error (may be null).
|
||||
*/
|
||||
public MathUserException(Throwable cause,
|
||||
Object ... args) {
|
||||
this(null, cause, args);
|
||||
public MathUserException(final Throwable cause) {
|
||||
this(cause, LocalizedFormats.USER_EXCEPTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param pattern Message pattern explaining the cause of the error.
|
||||
* @param cause Cause of the error.
|
||||
* @param args Arguments.
|
||||
* Build an exception with a localizable message.
|
||||
* @param pattern Format specifier.
|
||||
* @param arguments Format arguments.
|
||||
*/
|
||||
public MathUserException(Localizable pattern,
|
||||
Throwable cause,
|
||||
Object ... args) {
|
||||
this.pattern = pattern;
|
||||
arguments = ArgUtils.flatten(args);
|
||||
public MathUserException(final Localizable pattern, final Object ... arguments) {
|
||||
this((Throwable) null, pattern, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an exception with a localizable message.
|
||||
* @param cause Cause of the error (may be null).
|
||||
* @param pattern Format specifier.
|
||||
* @param arguments Format arguments.
|
||||
*/
|
||||
public MathUserException(final Throwable cause,
|
||||
final Localizable pattern, final Object ... arguments) {
|
||||
this(cause, (Localizable) null, pattern, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an exception from two patterns (specific and general) and
|
||||
* an argument list.
|
||||
*
|
||||
* @param specific Format specifier for the specific part (may be null).
|
||||
* @param general Format specifier for the general part (may be null).
|
||||
* @param arguments Format arguments. They will be substituted in
|
||||
* <em>both</em> the {@code general} and {@code specific} format specifiers.
|
||||
*/
|
||||
public MathUserException(final Localizable specific, final Localizable general,
|
||||
final Object ... arguments) {
|
||||
this((Throwable) null, specific, general, arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an exception from two patterns (specific and general) and
|
||||
* an argument list.
|
||||
*
|
||||
* @param cause Cause of the error (may be null).
|
||||
* @param specific Format specifier for the specific part (may be null).
|
||||
* @param general Format specifier for the general part (may be null).
|
||||
* @param arguments Format arguments. They will be substituted in
|
||||
* <em>both</em> the {@code general} and {@code specific} format specifiers.
|
||||
*/
|
||||
public MathUserException(final Throwable cause,
|
||||
final Localizable specific, final Localizable general,
|
||||
final Object ... arguments) {
|
||||
super(cause);
|
||||
this.specific = specific;
|
||||
this.general = general;
|
||||
this.arguments = ArgUtils.flatten(arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,10 +123,7 @@ public class MathUserException extends RuntimeException {
|
|||
* @return the localized message.
|
||||
*/
|
||||
public String getMessage(final Locale locale) {
|
||||
return MessageFactory.buildMessage(locale,
|
||||
pattern,
|
||||
LocalizedFormats.USER_EXCEPTION,
|
||||
arguments);
|
||||
return MessageFactory.buildMessage(locale, specific, general, arguments);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
|
Loading…
Reference in New Issue