Top Description Methods
org.apache.commons.lang3.exception

public Interface ExceptionContext

Known Direct Implementers
org.apache.commons.lang3.exception.ContextedException, org.apache.commons.lang3.exception.ContextedRuntimeException, org.apache.commons.lang3.exception.DefaultExceptionContext
Imports
java.util.List, .Set, org.apache.commons.lang3.tuple.Pair

Allows the storage and retrieval of contextual information based on label-value pairs for exceptions.

Implementations are expected to manage the pairs in a list-style collection that keeps the pairs in the sequence of their addition.

Since
3.0
See Also
ContextedException, ContextedRuntimeException

Method Summary

Modifier and TypeMethod and Description
public ExceptionContext

Returns:

this, for method chaining, not null
addContextValue
(String
the label of the item to add, null not recommended
label
,
Object
the value of item to add, may be null
value
)

Adds a contextual label-value pair into this context.

public List<Pair<String, Object>>

Returns:

the list of pairs, not null
getContextEntries
()

Gets the full list of label-value pairs defined in the contextual data.

public Set<String>

Returns:

the set of labels, not null
getContextLabels
()

Gets the full set of labels defined in the contextual data.

public List<Object>

Returns:

the contextual values associated with the label, never null
getContextValues
(String
the label to get the contextual values for, may be null
label
)

Gets all the contextual data values associated with the label.

public Object

Returns:

the first contextual value associated with the label, may be null
getFirstContextValue
(String
the label to get the contextual value for, may be null
label
)

Gets the first available contextual data value associated with the label.

public String

Returns:

the exception message with context information appended, not null
getFormattedExceptionMessage
(String
the base exception message without context information appended
baseMessage
)

Gets the contextualized error message based on a base message.

public ExceptionContext

Returns:

this, for method chaining, not null
setContextValue
(String
the label of the item to add, null not recommended
label
,
Object
the value of item to add, may be null
value
)

Sets a contextual label-value pair into this context.

Method Detail

addContextValueback to summary
public ExceptionContext addContextValue(String label, Object value)

Adds a contextual label-value pair into this context.

The pair will be added to the context, independently of an already existing pair with the same label.

Parameters
label:String

the label of the item to add, null not recommended

value:Object

the value of item to add, may be null

Returns:ExceptionContext

this, for method chaining, not null

getContextEntriesback to summary
public List<Pair<String, Object>> getContextEntries()

Gets the full list of label-value pairs defined in the contextual data.

Returns:List<Pair<String, Object>>

the list of pairs, not null

getContextLabelsback to summary
public Set<String> getContextLabels()

Gets the full set of labels defined in the contextual data.

Returns:Set<String>

the set of labels, not null

getContextValuesback to summary
public List<Object> getContextValues(String label)

Gets all the contextual data values associated with the label.

Parameters
label:String

the label to get the contextual values for, may be null

Returns:List<Object>

the contextual values associated with the label, never null

getFirstContextValueback to summary
public Object getFirstContextValue(String label)

Gets the first available contextual data value associated with the label.

Parameters
label:String

the label to get the contextual value for, may be null

Returns:Object

the first contextual value associated with the label, may be null

getFormattedExceptionMessageback to summary
public String getFormattedExceptionMessage(String baseMessage)

Gets the contextualized error message based on a base message. This will add the context label-value pairs to the message.

Parameters
baseMessage:String

the base exception message without context information appended

Returns:String

the exception message with context information appended, not null

setContextValueback to summary
public ExceptionContext setContextValue(String label, Object value)

Sets a contextual label-value pair into this context.

The pair will be added normally, but any existing label-value pair with the same label is removed from the context.

Parameters
label:String

the label of the item to add, null not recommended

value:Object

the value of item to add, may be null

Returns:ExceptionContext

this, for method chaining, not null