Interface FatalErrorHandler

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface FatalErrorHandler
A callback for any fatal (unchecked) exceptions

Also contains various default handlers

  • Method Details

    • handle

      void handle(Throwable e, @Nullable @Nullable Object context)
      Called when an unchecked exception is caught during execution of some task
      Parameters:
      e - the caught exception
      context - the context in which exception was caught in, possibly null
    • handle

      default void handle(Throwable e)
      Called when an unchecked exception is caught during execution of some task
      Parameters:
      e - the caught exception
      See Also:
    • andThen

      default FatalErrorHandler andThen(FatalErrorHandler nextHandler)
      Combines handlers by chaining the next handler after the current one
    • setThreadFatalErrorHandler

      static void setThreadFatalErrorHandler(@Nullable @Nullable FatalErrorHandler handler)
      Sets a fatal error handler for a current thread
      Parameters:
      handler - a global fatal error handler
    • setGlobalFatalErrorHandler

      static void setGlobalFatalErrorHandler(FatalErrorHandler handler)
      Sets a global fatal error handler. This handler will be used if no other handler was set for a handling thread using setThreadFatalErrorHandler(FatalErrorHandler)
      Parameters:
      handler - a global fatal error handler
    • getCurrent

      static FatalErrorHandler getCurrent()
      Returns a thread fatal error handler. If no thread fatal error handler was set using setThreadFatalErrorHandler(FatalErrorHandler), a global fatal error handler will be returned
      Returns:
      a thread fatal error handler or a global fatal error handler if thread's handler was not set
    • handleError

      static void handleError(FatalErrorHandler fatalErrorHandler, Throwable e, @Nullable @Nullable Object context)
      Uses a given fatal error handler to handle a received Throwable

      If an error is a checked exception, no handling will be performed

      An optional context may be passed for debug purposes

      Parameters:
      fatalErrorHandler - a fatal error handler
      e - an error to be handled
      context - an optional context that provides additional debug information
      See Also:
    • handleError

      static void handleError(Throwable e, @Nullable @Nullable Object context)
      Uses current thread's fatal error handler to handle a received Throwable

      If no error handler is set for the current thread, uses a global fatal error handler

      If an error is a checked exception, no handling will be performed

      An optional context may be passed for debug purposes

      Parameters:
      e - an error to be handled
      context - an optional context that provides additional debug information
      See Also:
    • handleError

      static void handleError(Throwable e)
      Uses current thread's fatal error handler to handle a received Throwable
      See Also:
    • getExceptionOrThrowError

      static Exception getExceptionOrThrowError(Throwable t)