Class FatalErrorHandlers

java.lang.Object
io.activej.common.exception.FatalErrorHandlers

public final class FatalErrorHandlers extends Object
Utility methods that allow to handle fatal errors using thread-specific handlers
  • Constructor Details

    • FatalErrorHandlers

      public FatalErrorHandlers()
  • Method Details

    • setThreadFatalErrorHandler

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

      public static void setGlobalFatalErrorHandler(@NotNull @NotNull 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
    • getFatalErrorHandler

      @NotNull public static @NotNull FatalErrorHandler getFatalErrorHandler()
      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

      public static void handleError(@NotNull @NotNull FatalErrorHandler fatalErrorHandler, @NotNull @NotNull 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

      public static void handleError(@NotNull @NotNull 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

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

      @NotNull public static @NotNull Exception getExceptionOrThrowError(@NotNull @NotNull Throwable t)