diff --git a/src/main/java/org/apache/commons/math/exception/MathUserException.java b/src/main/java/org/apache/commons/math/exception/MathUserException.java
index 4566d515e..f60293c4c 100644
--- a/src/main/java/org/apache/commons/math/exception/MathUserException.java
+++ b/src/main/java/org/apache/commons/math/exception/MathUserException.java
@@ -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
+ * both 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
+ * both 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} */