On this page

DefaultExceptionContext

public class org.apache.commons.lang3.exception.DefaultExceptionContext implements ExceptionContext, Serializable[source]

Default implementation of the context storing the label-value pairs for contexted exceptions.

This implementation is serializable, however this is dependent on the values that are added also being serializable.

Since:

3.0

See also:

Constructors

DefaultExceptionContext()

Constructs a new instance.

public DefaultExceptionContext()[source]

Constructs a new instance.

Methods

DefaultExceptionContext

addContextValue(String label, Object value)

Adds a contextual label-value pair into this context.

List<Pair<String, Object>>

getContextEntries()

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

Set<String>

getContextLabels()

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

List<Object>

getContextValues(String label)

Gets all the contextual data values associated with the label.

Object

getFirstContextValue(String label)

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

String

getFormattedExceptionMessage(String baseMessage)

Gets the message containing the contextual information.

DefaultExceptionContext

setContextValue(String label, Object value)

Sets a contextual label-value pair into this context.

public DefaultExceptionContext 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.

Specified by:

addContextValue in interface ExceptionContext

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 List<Pair<String, Object>> getContextEntries()[source]

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

Specified by:

getContextEntries in interface ExceptionContext

Returns:

The list of pairs, not null

public Set<String> getContextLabels()[source]

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

Specified by:

getContextLabels in interface ExceptionContext

Returns:

The set of labels, not null

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

Gets all the contextual data values associated with the label.

Specified by:

getContextValues in interface ExceptionContext

Parameters:

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

Returns:

The contextual values associated with the label, never null

public Object getFirstContextValue(String label)[source]

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

Specified by:

getFirstContextValue in interface ExceptionContext

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 String getFormattedExceptionMessage(String baseMessage)[source]

Gets the message containing the contextual information.

Specified by:

getFormattedExceptionMessage in interface ExceptionContext

Parameters:

baseMessage – The base exception message without context information appended

Returns:

The exception message with context information appended, never null

public DefaultExceptionContext 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.

Specified by:

setContextValue in interface ExceptionContext

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