Class ProcessorExceptionHandler

java.lang.Object
pro.verron.docxstamper.utils.ProcessorExceptionHandler
All Implemented Interfaces:
Thread.UncaughtExceptionHandler

public class ProcessorExceptionHandler extends Object implements 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:
${version}
Author:
Joseph Verron
See Also:
  • 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

      public void uncaughtException(Thread t, Throwable e)
      Captures and stores an uncaught exception from a thread run and executes all defined routines on occurrence of the exception.
      Specified by:
      uncaughtException in interface Thread.UncaughtExceptionHandler
    • onException

      public void onException(ThrowingRunnable runnable)
      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

      public Optional<Throwable> exception()
      Returns the captured exception if present.
      Returns:
      an Optional containing the captured exception, or an empty Optional if no exception was captured