Class ErrorHandler

java.lang.Object
com.j3d.errors.ErrorHandler

public class ErrorHandler extends Object
Centralized error handling mechanism for J3Engine.

This class provides methods to handle various types of J3DErrors, categorising them by their severity (mild, warning, fatal) and performing appropriate actions such as logging, displaying user messages, or terminating the application. It also supports temporarily ignoring specific error types.

Author:
Lehlogonolo Poole
See Also:
  • Field Details

  • Constructor Details

    • ErrorHandler

      public ErrorHandler()
  • Method Details

    • ignore

      public <T extends J3DError> void ignore(Class<T> err)
      Registers a specific J3DError class to be ignored by the error handler. When an error of the registered class type is encountered by the handle(J3DError) method, it will be consumed (removed from the ignore list) and no further action will be taken. This effectively makes the next occurrence of that specific error type to be silently handled.
      Type Parameters:
      T - The type of J3DError to ignore.
      Parameters:
      err - The Class object of the J3DError to be ignored.
      Throws:
      RuntimeException - if more than 10 error classes are attempted to be ignored.
    • handle

      public void handle(J3DError err)
      Handles a given J3DError, processing it based on its type and severity.

      If the error is registered to be ignored, that is handled

      Otherwise, the error is processed based on its specific type:

      • J3DMild: The error is printed to the application's log.
      • J3DWarning: The error is printed to the application's log, and a warning message dialogue is displayed to the user.
      • J3DFatal: The error is printed to the application's log, and a fatal error message dialogue is displayed to the user. If the fatal error's terminate() method returns true, an additional message is shown, and the application is terminated via System.exit(1).
      • Any other J3DError type (that is also an instance of J3ErrSeverity): The error is simply printed to the application's log.
      Parameters:
      err - The J3DError instance to be handled.
    • handleThenThrow

      public void handleThenThrow(J3DError err) throws J3DError
      Handles a given J3DError using the handle(J3DError) method and then re-throws it.
      Parameters:
      err - The J3DError instance to be handled and thrown.
      Throws:
      J3DError - The same J3DError instance that was passed in, after it has been processed by the handle(J3DError) method.