Package com.github.dakusui.exception
Interface ExceptionContext<K extends ExceptionContext.Key>
- Type Parameters:
K- Type of key in this context.
- All Superinterfaces:
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
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordExceptionContext.Entry<K extends ExceptionContext.Key>An entry that can be registered in theExceptionContext.static classA factory of anExceptionContextobject.static interfaceAn interface for keys to be used forExceptionContext.static classA manager class of anExceptionContext. -
Method Summary
Modifier and TypeMethodDescriptionstatic <K extends ExceptionContext.Key>
ExceptionContext.Entry<K> A shorthand method forentry(Key, Object).default voidclose()data()Returns entries in the current Context.static <K extends ExceptionContext.Key>
ExceptionContext.Entry<K> Creates and returns anEntryobject.manager()Returns a manager of this object.parent()Returns a parent of this object, if any.default <T> TReturns a value forkey.
-
Method Details
-
valueFor
Returns a value for
key.Kshould extend anEnumand therefore, a key which doesn’t have a mapped value must not be looked up. When looked up, behavior is not defined andAssertionErrormay 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
Optional<ExceptionContext<K>> parent()Returns a parent of this object, if any.
- Returns:
- A parent context of this object.
-
data
Returns entries in the current Context.
- Returns:
- A map that holds entries in the current Context.
-
manager
ExceptionContext.Manager<K> manager()Returns a manager of this object.
- Returns:
- A manager object.
-
close
default void close()- Specified by:
closein interfaceAutoCloseable
-
entry
Creates and returns an
Entryobject.- Type Parameters:
K- Type of key.- Parameters:
key- A key of an entryvalue- A value of an entry- Returns:
- An entry object.
- See Also:
-
$
A shorthand method for
entry(Key, Object). Dostatic importto 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:
-