Package org.apache.drill.common
Class DeferredException
java.lang.Object
org.apache.drill.common.DeferredException
- All Implemented Interfaces:
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 Summary
ConstructorDescriptionConstructor.DeferredException
(org.apache.drill.shaded.guava.com.google.common.base.Supplier<Exception> exceptionSupplier) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addException
(Exception exception) Add an exception.void
addThrowable
(Throwable throwable) void
close()
Get the deferred exception, if there is one.void
suppressingClose
(AutoCloseable autoCloseable) Close the given AutoCloseable, suppressing any exceptions that are thrown.void
If an exception exists, will throw the exception and then clear it.
-
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
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
-
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
-
throwAndClear
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
Close the given AutoCloseable, suppressing any exceptions that are thrown. If an exception is thrown, the rules foraddException(Exception)
are followed.- Parameters:
autoCloseable
- the AutoCloseable to close; may be null
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-