Interface ExceptionContext<K extends ExceptionContext.Key>

Type Parameters:
K - Type of key in this context.
All Superinterfaces:
AutoCloseable

public interface ExceptionContext<K extends ExceptionContext.Key> extends AutoCloseable

An interface that models a context that handles exceptions. This provides a mechanism to print meaningful exception messages utilizing contextual information.

K should be a subclass of an Enum, but users can use non-subclass of it at the risk of their own.a

  • Method Details

    • valueFor

      default <T> T valueFor(K key)

      Returns a value for key. K should extend an Enum and therefore, a key which doesn’t have a mapped value must not be looked up. When looked up, behavior is not defined and AssertionError may be thrown.

      Type Parameters:
      T - Type of the value to be returned.
      Parameters:
      key - A key whose value should be looked up by this method.
      Returns:
      A value for key.
    • parent

      Returns a parent of this object, if any.

      Returns:
      A parent context of this object.
    • data

      Map<K,Object> data()

      Returns entries in the current Context.

      Returns:
      A map that holds entries in the current Context.
    • manager

      Returns a manager of this object.

      Returns:
      A manager object.
    • close

      default void close()
      Specified by:
      close in interface AutoCloseable
    • entry

      static <K extends ExceptionContext.Key> ExceptionContext.Entry<K> entry(K key, Object value)

      Creates and returns an Entry object.

      Type Parameters:
      K - Type of key.
      Parameters:
      key - A key of an entry
      value - A value of an entry
      Returns:
      An entry object.
      See Also:
    • $

      static <K extends ExceptionContext.Key> ExceptionContext.Entry<K> $(K key, Object value)

      A shorthand method for entry(Key, Object). Do static import to use this method to make your code look concise.

      Type Parameters:
      K - Type of key
      Parameters:
      key - A key of an entry.
      value - A value of an entry.
      Returns:
      An entry.
      See Also: