Class Throwables

java.lang.Object
org.apache.pekko.japi.Throwables

public class Throwables extends Object
Helper class for determining whether a Throwable is fatal or not. User should only catch the non-fatal one,and keep rethrow the fatal one.

Fatal errors are errors like VirtualMachineError (for example, OutOfMemoryError and StackOverflowError, subclasses of VirtualMachineError), ThreadDeath, LinkageError, InterruptedException, ControlThrowable.

Note. this helper keep the same semantic with NonFatal in Scala. For example, all harmless Throwables can be caught by:


   try {
     // dangerous stuff
   } catch(Throwable e) {
     if (Throwables.isNonFatal(e)){
       log.error(e, "Something not that bad.");
     } else {
       throw e;
     }
 
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    isFatal(Throwable throwable)
    Returns true if the provided Throwable is to be considered fatal, or false if it is to be considered non-fatal
    static boolean
    isNonFatal(Throwable throwable)
    Returns true if the provided Throwable is to be considered non-fatal, or false if it is to be considered fatal
    static <T extends Throwable, R>
    R
    Throws the given Throwable, without requiring the caller to declare it in a throws clause.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Throwables

      public Throwables()
  • Method Details

    • isNonFatal

      public static boolean isNonFatal(Throwable throwable)
      Returns true if the provided Throwable is to be considered non-fatal, or false if it is to be considered fatal
    • isFatal

      public static boolean isFatal(Throwable throwable)
      Returns true if the provided Throwable is to be considered fatal, or false if it is to be considered non-fatal
    • sneakyThrow

      public static <T extends Throwable, R> R sneakyThrow(Throwable t)
      Throws the given Throwable, without requiring the caller to declare it in a throws clause.
      Parameters:
      t - the Throwable to throw
      Returns:
      never returns normally, but has return type R to allow usage in expressions
      Throws:
      T - the type of the Throwable to throw
      Since:
      2.0.0