ExceptionContext

public abstract interface org.apache.commons.lang3.exception.ExceptionContext[source]

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.

See also:
Since:

3.0

Methods

addContextValue(String, Object)

Adds a contextual label-value pair into this context.

getContextEntries()

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

getContextLabels()

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

getContextValues(String)

Gets all the contextual data values associated with the label.

getFirstContextValue(String)

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

getFormattedExceptionMessage(String)

Gets the contextualized error message based on a base message.

setContextValue(String, Object)

Sets a contextual label-value pair into this context.

public abstract ExceptionContext addContextValue(String label, Object value)[source]

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 – The label of the item to add, null not recommended

  • value – The value of item to add, may be null

Returns:

this, for method chaining, not null

public abstract List<Pair<String, Object>> getContextEntries()[source]

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

Returns:

The list of pairs, not null

public abstract Set<String> getContextLabels()[source]

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

Returns:

The set of labels, not null

public abstract List<Object> getContextValues(String label)[source]

Gets all the contextual data values associated with the label.

Parameters:

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

Returns:

The contextual values associated with the label, never null

public abstract Object getFirstContextValue(String label)[source]

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

Parameters:

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

Returns:

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

public abstract String getFormattedExceptionMessage(String baseMessage)[source]

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

Parameters:

baseMessage – The base exception message without context information appended

Returns:

The exception message with context information appended, not null

public abstract ExceptionContext setContextValue(String label, Object value)[source]

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 – The label of the item to add, null not recommended

  • value – The value of item to add, may be null

Returns:

this, for method chaining, not null