Class ExceptionContext
- java.lang.Object
-
- org.apache.commons.math4.exception.util.ExceptionContext
-
- All Implemented Interfaces:
java.io.Serializable
public class ExceptionContext extends java.lang.Object implements java.io.SerializableClass that contains the actual implementation of the functionality mandated by theExceptionContextinterface. All Commons Math exceptions delegate the interface's methods to this class.- Since:
- 3.0
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ExceptionContext(java.lang.Throwable throwable)Simple constructor.
-
Method Summary
Modifier and Type Method Description voidaddMessage(Localizable pattern, java.lang.Object... arguments)Adds a message.java.util.Set<java.lang.String>getKeys()Gets all the keys stored in the exceptionjava.lang.StringgetLocalizedMessage()Gets the message in the default locale.java.lang.StringgetMessage()Gets the default message.java.lang.StringgetMessage(java.util.Locale locale)Gets the message in a specified locale.java.lang.StringgetMessage(java.util.Locale locale, java.lang.String separator)Gets the message in a specified locale.java.lang.ThrowablegetThrowable()Get a reference to the exception to which the context relates.java.lang.ObjectgetValue(java.lang.String key)Gets the value associated to the given context key.voidsetValue(java.lang.String key, java.lang.Object value)Sets the context (key, value) pair.
-
-
-
Method Detail
-
getThrowable
public java.lang.Throwable getThrowable()
Get a reference to the exception to which the context relates.- Returns:
- a reference to the exception to which the context relates
-
addMessage
public void addMessage(Localizable pattern, java.lang.Object... arguments)
Adds a message.- Parameters:
pattern- Message pattern.arguments- Values for replacing the placeholders in the message pattern.
-
setValue
public void setValue(java.lang.String key, java.lang.Object value)Sets the context (key, value) pair. Keys are assumed to be unique within an instance. If the same key is assigned a new value, the previous one will be lost.- Parameters:
key- Context key (not null).value- Context value.
-
getValue
public java.lang.Object getValue(java.lang.String key)
Gets the value associated to the given context key.- Parameters:
key- Context key.- Returns:
- the context value or
nullif the key does not exist.
-
getKeys
public java.util.Set<java.lang.String> getKeys()
Gets all the keys stored in the exception- Returns:
- the set of keys.
-
getMessage
public java.lang.String getMessage()
Gets the default message.- Returns:
- the message.
-
getLocalizedMessage
public java.lang.String getLocalizedMessage()
Gets the message in the default locale.- Returns:
- the localized message.
-
getMessage
public java.lang.String getMessage(java.util.Locale locale)
Gets the message in a specified locale.- Parameters:
locale- Locale in which the message should be translated.- Returns:
- the localized message.
-
getMessage
public java.lang.String getMessage(java.util.Locale locale, java.lang.String separator)Gets the message in a specified locale.- Parameters:
locale- Locale in which the message should be translated.separator- Separator inserted between the message parts.- Returns:
- the localized message.
-
-