public class ThreadLocalisedExceptionHandler extends Object implements ExceptionHandler
ExceptionHandler.
The handler supplied to the constructor becomes the default. Each thread may
override this via threadLocalHandler(ExceptionHandler) and the override can
be removed with resetThreadLocalHandler().
Nested ChainedExceptionHandler instances are rejected by
defaultHandler(ExceptionHandler).
This class is conditionally thread-safe: the default handler is shared while
per-thread handlers are isolated using ThreadLocal.
ChainedExceptionHandler| Constructor and Description |
|---|
ThreadLocalisedExceptionHandler(ExceptionHandler handler)
Creates a new instance using the supplied handler as the default.
|
| Modifier and Type | Method and Description |
|---|---|
ExceptionHandler |
defaultHandler()
Returns the current default handler.
|
ThreadLocalisedExceptionHandler |
defaultHandler(ExceptionHandler defaultHandler)
Sets the default handler to use when no thread-local handler is present.
|
boolean |
isEnabled(@NotNull Class<?> aClass)
Checks if the exception handler is enabled for the given class.
|
void |
on(@NotNull Class<?> clazz,
@Nullable String message,
@Nullable Throwable thrown)
Handles an exception for the given class, message and throwable.
|
void |
on(@NotNull org.slf4j.Logger logger,
@Nullable String message,
Throwable thrown)
Handles an exception with the given logger, message and throwable.
|
void |
resetThreadLocalHandler()
Clears any thread specific handler so the default will be used.
|
ExceptionHandler |
threadLocalHandler()
Returns the handler specific to the current thread or
null if none is set. |
ThreadLocalisedExceptionHandler |
threadLocalHandler(ExceptionHandler handler)
Overrides the handler for the current thread.
|
static ExceptionHandler |
unwrap(ExceptionHandler eh)
Unwraps the supplied handler if it is an instance of this class.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitignoresEverything, on, on, onpublic ThreadLocalisedExceptionHandler(ExceptionHandler handler)
handler - the handler used when no thread-local handler is presentpublic void on(@NotNull
@NotNull Class<?> clazz,
@Nullable
@Nullable String message,
@Nullable
@Nullable Throwable thrown)
ExceptionHandlerSlf4jExceptionHandler.ERROR level.on in interface ExceptionHandlerclazz - the class where the exception occurredmessage - a custom message providing additional information or nullthrown - the exception that needs to be handled, may be nullpublic void on(@NotNull
@NotNull org.slf4j.Logger logger,
@Nullable
@Nullable String message,
Throwable thrown)
ExceptionHandleron in interface ExceptionHandlerlogger - the logger used to record the errormessage - a custom message detailing the error, may be nullthrown - the throwable instance representing the error, may be nullpublic ExceptionHandler defaultHandler()
defaultHandler in interface ExceptionHandlerpublic static ExceptionHandler unwrap(ExceptionHandler eh)
eh - the handler to unwrappublic ThreadLocalisedExceptionHandler defaultHandler(ExceptionHandler defaultHandler)
ChainedExceptionHandler instances are rejected.defaultHandler - the new default handler, or null to use
NullExceptionHandler.NOTHINGthis for chainingpublic ExceptionHandler threadLocalHandler()
null if none is set.nullpublic ThreadLocalisedExceptionHandler threadLocalHandler(ExceptionHandler handler)
handler - the handler to install for this thread, may be nullthis for chainingpublic void resetThreadLocalHandler()
public boolean isEnabled(@NotNull
@NotNull Class<?> aClass)
isEnabled in interface ExceptionHandleraClass - the class to testtrue if this handler should be invoked for the classCopyright © 2026 Chronicle Software Ltd. All rights reserved.