Package io.matita08

Class ExceptionHandler

java.lang.Object
io.matita08.ExceptionHandler
All Implemented Interfaces:
Thread.UncaughtExceptionHandler

public class ExceptionHandler extends Object implements Thread.UncaughtExceptionHandler
Custom uncaught exception handler for the CPU simulator application. This class implements Thread.UncaughtExceptionHandler to provide centralized exception handling with logging capabilities and graceful application shutdown.

The handler performs the following actions when an uncaught exception occurs:

  • Logs the exception to both console and a persistent log file
  • Identifies whether the exception occurred in the Swing Event Dispatch Thread
  • Provides different handling for GUI thread vs background thread exceptions
  • Terminates the application if critical GUI thread exceptions occur

Log files are created in a platform-appropriate application data directory with timestamps to ensure uniqueness and chronological organization.

Since:
1.0
  • Field Details

    • logStream

      public static final PrintStream logStream
      Print stream for writing to the log file. Provides formatted output for exception logging.
  • Constructor Details

    • ExceptionHandler

      public ExceptionHandler(boolean swingThread)
      Constructs a new ExceptionHandler with the specified thread type.
      Parameters:
      swingThread - true if this handler is for the Swing Event Dispatch Thread, false for background or utility threads
  • Method Details

    • uncaughtException

      public void uncaughtException(Thread t, Throwable e)
      Handles uncaught exceptions by logging them and taking appropriate action.

      For Swing EDT exceptions:

      • Logs a specific message indicating GUI thread failure
      • Prints stack trace to both console and log file
      • Terminates the application with exit code 3

      For other thread exceptions:

      • Logs the thread information
      • Prints stack trace to both console and log file
      • Allows the application to continue running
      Specified by:
      uncaughtException in interface Thread.UncaughtExceptionHandler
      Parameters:
      t - the thread that had the uncaught exception
      e - the exception that was thrown