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;
     }
 
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Throwables$
    Static reference to the singleton instance of this Scala object.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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
    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
    <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
  • Field Details

    • MODULE$

      public static final Throwables$ MODULE$
      Static reference to the singleton instance of this Scala object.
  • Constructor Details

    • Throwables$

      public Throwables$()
  • Method Details

    • isNonFatal

      public 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 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 <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