Package pro.verron.docxstamper.utils
Class ProcessorExceptionHandler
java.lang.Object
pro.verron.docxstamper.utils.ProcessorExceptionHandler
- All Implemented Interfaces:
Thread.UncaughtExceptionHandler
The ProcessorExceptionHandler class is responsible for capturing and handling uncaught exceptions that occur in a thread.
It implements the Thread.UncaughtExceptionHandler interface and can be assigned to a thread using the setUncaughtExceptionHandler() method.
When an exception occurs in the thread, the uncaughtException() method of ProcessorExceptionHandler will be called.
This class provides the following features:
1. Capturing and storing the uncaught exception.
2. Executing a list of routines when an exception occurs.
3. Providing access to the captured exception, if any.
Example usage:
ProcessorExceptionHandler exceptionHandler = new ProcessorExceptionHandler();
thread.setUncaughtExceptionHandler(exceptionHandler);
- Version:
- 1.6.6
- Author:
- Joseph Verron
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new ProcessorExceptionHandler for managing thread's uncaught exceptions. -
Method Summary
Modifier and TypeMethodDescriptionReturns the captured exception if present.voidonException(ThrowingRunnable runnable) Adds a routine to the list of routines that should be run when an exception occurs.voiduncaughtException(Thread t, Throwable e) Captures and stores an uncaught exception from a thread run and executes all defined routines on occurrence of the exception.
-
Constructor Details
-
ProcessorExceptionHandler
public ProcessorExceptionHandler()Constructs a new ProcessorExceptionHandler for managing thread's uncaught exceptions. Once set to a thread, it retains the exception information and performs specified routines.
-
-
Method Details
-
uncaughtException
Captures and stores an uncaught exception from a thread run and executes all defined routines on occurrence of the exception.- Specified by:
uncaughtExceptionin interfaceThread.UncaughtExceptionHandler
-
onException
Adds a routine to the list of routines that should be run when an exception occurs.- Parameters:
runnable- The runnable routine to be added
-
exception
Returns the captured exception if present.- Returns:
- an Optional containing the captured exception, or an empty Optional if no exception was captured
-