Class DeferredException

java.lang.Object
org.apache.drill.common.DeferredException
All Implemented Interfaces:
AutoCloseable

public class DeferredException extends Object implements AutoCloseable
Collects one or more exceptions that may occur, using suppressed exceptions. When this AutoCloseable is closed, if there was an exception added, it will be thrown. If more than one exception was added, then all but the first will be added to the first as suppressed exceptions.

This class is thread safe.

  • Constructor Details

    • DeferredException

      public DeferredException()
      Constructor.
    • DeferredException

      public DeferredException(org.apache.drill.shaded.guava.com.google.common.base.Supplier<Exception> exceptionSupplier)
      Constructor. This constructor accepts a Supplier that can be used to create the root exception iff any other exceptions are added. For example, in a series of resources closures in a close(), if any of the individual closures fails, the root exception should come from the current class, not from the first subordinate close() to fail. This can be used to provide an exception in that case which will be the root exception; the subordinate failed close() will be added to that exception as a suppressed exception.
      Parameters:
      exceptionSupplier - lazily supplies what will be the root exception if any exceptions are added
  • Method Details

    • addException

      public void addException(Exception exception)
      Add an exception. If this is the first exception added, it will be the one that is thrown when this is closed. If not the first exception, then it will be added to the suppressed exceptions on the first exception.
      Parameters:
      exception - the exception to add
    • addThrowable

      public void addThrowable(Throwable throwable)
    • getException

      public Exception getException()
      Get the deferred exception, if there is one. Note that if this returns null, the result could change at any time.
      Returns:
      the deferred exception, or null
    • getAndClear

      public Exception getAndClear()
    • throwAndClear

      public void throwAndClear() throws Exception
      If an exception exists, will throw the exception and then clear it. This is so in cases where want to reuse DeferredException, we don't double report the same exception.
      Throws:
      Exception
    • suppressingClose

      public void suppressingClose(AutoCloseable autoCloseable)
      Close the given AutoCloseable, suppressing any exceptions that are thrown. If an exception is thrown, the rules for addException(Exception) are followed.
      Parameters:
      autoCloseable - the AutoCloseable to close; may be null
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception