AutoCloseable
.-
Method Summary
Modifier and TypeMethodDescriptionstatic Throwable
closeAndCatch
(AutoCloseable closeable) Closes the givenAutoCloseable
, catching allThrowable
.static Throwable
closeAndCatch
(AutoCloseable... closeable) Closes all of the givenAutoCloseable
in order, catching allThrowable
.static Throwable
closeAndCatch
(Iterable<? extends AutoCloseable> closeable) Closes all of the givenAutoCloseable
in order, catching allThrowable
.static Throwable
closeAndCatch
(Throwable t0, AutoCloseable closeable) Closes the givenAutoCloseable
, catching allThrowable
.static Throwable
closeAndCatch
(Throwable t0, AutoCloseable... closeable) Closes all of the givenAutoCloseable
in order, catching allThrowable
.static Throwable
closeAndCatch
(Throwable t0, Iterable<? extends AutoCloseable> closeable) Closes all of the givenAutoCloseable
in order, catching allThrowable
.static <Ex extends Throwable>
voidcloseAndThrow
(Class<? extends Ex> exClass, Function<? super Throwable, ? extends Ex> exSupplier, AutoCloseable closeable) Closes the givenAutoCloseable
in order, throwing allThrowable
, wrapping when needed.static <Ex extends Throwable>
voidcloseAndThrow
(Class<? extends Ex> exClass, Function<? super Throwable, ? extends Ex> exSupplier, AutoCloseable... closeable) Closes all of the givenAutoCloseable
in order, throwing allThrowable
, wrapping when needed.static <Ex extends Throwable>
voidcloseAndThrow
(Class<? extends Ex> exClass, Function<? super Throwable, ? extends Ex> exSupplier, Iterable<? extends AutoCloseable> closeable) Closes all of the givenAutoCloseable
in order, throwing allThrowable
, wrapping when needed.static <Ex extends Throwable>
voidcloseAndThrow
(Throwable t0, Class<? extends Ex> exClass, Function<? super Throwable, ? extends Ex> exSupplier, AutoCloseable closeable) Closes the givenAutoCloseable
in order, throwing allThrowable
, wrapping when needed.static <Ex extends Throwable>
voidcloseAndThrow
(Throwable t0, Class<? extends Ex> exClass, Function<? super Throwable, ? extends Ex> exSupplier, AutoCloseable... closeable) Closes all of the givenAutoCloseable
in order, throwing allThrowable
, wrapping when needed.static <Ex extends Throwable>
voidcloseAndThrow
(Throwable t0, Class<? extends Ex> exClass, Function<? super Throwable, ? extends Ex> exSupplier, Iterable<? extends AutoCloseable> closeable) Closes all of the givenAutoCloseable
in order, throwing allThrowable
, wrapping when needed.static <Ex extends Throwable>
ExcloseAndWrap
(Throwable t0, Class<? extends Ex> exClass, Function<? super Throwable, ? extends Ex> exSupplier, AutoCloseable closeable) Closes the givenAutoCloseable
, catching allThrowable
.static <Ex extends Throwable>
ExcloseAndWrap
(Throwable t0, Class<? extends Ex> exClass, Function<? super Throwable, ? extends Ex> exSupplier, AutoCloseable... closeable) Closes all of the givenAutoCloseable
in order, catching allThrowable
.static <Ex extends Throwable>
ExcloseAndWrap
(Throwable t0, Class<? extends Ex> exClass, Function<? super Throwable, ? extends Ex> exSupplier, Iterable<? extends AutoCloseable> closeable) Closes all of the givenAutoCloseable
in order, catching allThrowable
.
-
Method Details
-
closeAndCatch
Closes the givenAutoCloseable
, catching allThrowable
.See
Throwables.addSuppressed(java.lang.Throwable, java.lang.Throwable)
for details on howThreadDeath
andInterruptedException
are managed.- Parameters:
t0
- If notnull
, any new throwables will be combined viaThrowables.addSuppressed(java.lang.Throwable, java.lang.Throwable)
closeable
- The closeable to be closed- Returns:
t0
, a new throwable, ornull
when none given and none new
-
closeAndCatch
Closes the givenAutoCloseable
, catching allThrowable
.See
Throwables.addSuppressed(java.lang.Throwable, java.lang.Throwable)
for details on howThreadDeath
andInterruptedException
are managed.- Parameters:
closeable
- The closeable to be closed- Returns:
- A new throwable or
null
-
closeAndCatch
Closes all of the givenAutoCloseable
in order, catching allThrowable
.See
Throwables.addSuppressed(java.lang.Throwable, java.lang.Throwable)
for details on howThreadDeath
andInterruptedException
are managed.- Parameters:
t0
- If notnull
, any new throwables will be combined viaThrowables.addSuppressed(java.lang.Throwable, java.lang.Throwable)
closeable
- The set of all closeables, which will be closed in order- Returns:
t0
, a new throwable, ornull
when none given and none new
-
closeAndCatch
Closes all of the givenAutoCloseable
in order, catching allThrowable
.See
Throwables.addSuppressed(java.lang.Throwable, java.lang.Throwable)
for details on howThreadDeath
andInterruptedException
are managed.- Parameters:
closeable
- The set of all closeables, which will be closed in order- Returns:
- A new throwable or
null
-
closeAndCatch
Closes all of the givenAutoCloseable
in order, catching allThrowable
.See
Throwables.addSuppressed(java.lang.Throwable, java.lang.Throwable)
for details on howThreadDeath
andInterruptedException
are managed.- Parameters:
t0
- If notnull
, any new throwables will be combined viaThrowables.addSuppressed(java.lang.Throwable, java.lang.Throwable)
closeable
- The set of all closeables, which will be closed in order- Returns:
t0
, a new throwable, ornull
when none given and none new
-
closeAndCatch
Closes all of the givenAutoCloseable
in order, catching allThrowable
.See
Throwables.addSuppressed(java.lang.Throwable, java.lang.Throwable)
for details on howThreadDeath
andInterruptedException
are managed.- Parameters:
closeable
- The set of all closeables, which will be closed in order- Returns:
- A new throwable or
null
-
closeAndThrow
public static <Ex extends Throwable> void closeAndThrow(Throwable t0, Class<? extends Ex> exClass, Function<? super Throwable, ? extends Ex> exSupplier, AutoCloseable closeable) throws Error, RuntimeException, ExCloses the givenAutoCloseable
in order, throwing allThrowable
, wrapping when needed.Only returns when
t0
isnull
and no new throwables.When the exception is an
InterruptedException
and is wrapped viaexSupplier
, and the resulting wrapper is not itself anInterruptedException
, the current thread will be re-interrupted.- Parameters:
t0
- If notnull
, any new throwables will be combined viaThrowables.addSuppressed(java.lang.Throwable, java.lang.Throwable)
exClass
- Throwables of this class, as well asError
andRuntimeException
, are thrown directly.exSupplier
- Other throwables are wrapped via this function, then throwncloseable
- The closeable to be closed- Throws:
Error
- When resolved throwable is anError
RuntimeException
- When resolved throwable is aRuntimeException
Ex
- When resolved throwable is an instance ofexClass
, otherwise wrapped viaexSupplier
-
closeAndThrow
public static <Ex extends Throwable> void closeAndThrow(Class<? extends Ex> exClass, Function<? super Throwable, ? extends Ex> exSupplier, AutoCloseable closeable) throws Error, RuntimeException, ExCloses the givenAutoCloseable
in order, throwing allThrowable
, wrapping when needed.Only returns when no throwables.
When the exception is an
InterruptedException
and is wrapped viaexSupplier
, and the resulting wrapper is not itself anInterruptedException
, the current thread will be re-interrupted.- Parameters:
exClass
- Throwables of this class, as well asError
andRuntimeException
, are thrown directly.exSupplier
- Other throwables are wrapped via this function, then throwncloseable
- The closeable to be closed- Throws:
Error
- When resolved throwable is anError
RuntimeException
- When resolved throwable is aRuntimeException
Ex
- When resolved throwable is an instance ofexClass
, otherwise wrapped viaexSupplier
-
closeAndThrow
public static <Ex extends Throwable> void closeAndThrow(Throwable t0, Class<? extends Ex> exClass, Function<? super Throwable, ? extends Ex> exSupplier, AutoCloseable... closeable) throws Error, RuntimeException, ExCloses all of the givenAutoCloseable
in order, throwing allThrowable
, wrapping when needed.Only returns when
t0
isnull
and no new throwables.When the exception is an
InterruptedException
and is wrapped viaexSupplier
, and the resulting wrapper is not itself anInterruptedException
, the current thread will be re-interrupted.- Parameters:
t0
- If notnull
, any new throwables will be combined viaThrowables.addSuppressed(java.lang.Throwable, java.lang.Throwable)
exClass
- Throwables of this class, as well asError
andRuntimeException
, are thrown directly.exSupplier
- Other throwables are wrapped via this function, then throwncloseable
- The set of all closeables, which will be closed in order- Throws:
Error
- When resolved throwable is anError
RuntimeException
- When resolved throwable is aRuntimeException
Ex
- When resolved throwable is an instance ofexClass
, otherwise wrapped viaexSupplier
-
closeAndThrow
public static <Ex extends Throwable> void closeAndThrow(Class<? extends Ex> exClass, Function<? super Throwable, ? extends Ex> exSupplier, AutoCloseable... closeable) throws Error, RuntimeException, ExCloses all of the givenAutoCloseable
in order, throwing allThrowable
, wrapping when needed.Only returns when no throwables.
When the exception is an
InterruptedException
and is wrapped viaexSupplier
, and the resulting wrapper is not itself anInterruptedException
, the current thread will be re-interrupted.- Parameters:
exClass
- Throwables of this class, as well asError
andRuntimeException
, are thrown directly.exSupplier
- Other throwables are wrapped via this function, then throwncloseable
- The set of all closeables, which will be closed in order- Throws:
Error
- When resolved throwable is anError
RuntimeException
- When resolved throwable is aRuntimeException
Ex
- When resolved throwable is an instance ofexClass
, otherwise wrapped viaexSupplier
-
closeAndThrow
public static <Ex extends Throwable> void closeAndThrow(Throwable t0, Class<? extends Ex> exClass, Function<? super Throwable, ? extends Ex> exSupplier, Iterable<? extends AutoCloseable> closeable) throws Error, RuntimeException, ExCloses all of the givenAutoCloseable
in order, throwing allThrowable
, wrapping when needed.Only returns when
t0
isnull
and no new throwables.When the exception is an
InterruptedException
and is wrapped viaexSupplier
, and the resulting wrapper is not itself anInterruptedException
, the current thread will be re-interrupted.- Parameters:
t0
- If notnull
, any new throwables will be combined viaThrowables.addSuppressed(java.lang.Throwable, java.lang.Throwable)
exClass
- Throwables of this class, as well asError
andRuntimeException
, are thrown directly.exSupplier
- Other throwables are wrapped via this function, then throwncloseable
- The set of all closeables, which will be closed in order- Throws:
Error
- When resolved throwable is anError
RuntimeException
- When resolved throwable is aRuntimeException
Ex
- When resolved throwable is an instance ofexClass
, otherwise wrapped viaexSupplier
-
closeAndThrow
public static <Ex extends Throwable> void closeAndThrow(Class<? extends Ex> exClass, Function<? super Throwable, ? extends Ex> exSupplier, Iterable<? extends AutoCloseable> closeable) throws Error, RuntimeException, ExCloses all of the givenAutoCloseable
in order, throwing allThrowable
, wrapping when needed.Only returns when no throwables.
When the exception is an
InterruptedException
and is wrapped viaexSupplier
, and the resulting wrapper is not itself anInterruptedException
, the current thread will be re-interrupted.- Parameters:
exClass
- Throwables of this class, as well asError
andRuntimeException
, are thrown directly.exSupplier
- Other throwables are wrapped via this function, then throwncloseable
- The set of all closeables, which will be closed in order- Throws:
Error
- When resolved throwable is anError
RuntimeException
- When resolved throwable is aRuntimeException
Ex
- When resolved throwable is an instance ofexClass
, otherwise wrapped viaexSupplier
-
closeAndWrap
public static <Ex extends Throwable> Ex closeAndWrap(Throwable t0, Class<? extends Ex> exClass, Function<? super Throwable, ? extends Ex> exSupplier, AutoCloseable closeable) Closes the givenAutoCloseable
, catching allThrowable
. Wraps any resulting throwable, unless is an instance ofexClass
,Error
, orRuntimeException
.- When
null
, returnsnull
. - When is an instance of
exClass
, returns the exception. - When is
Error
orRuntimeException
, throws the exception directly. - Otherwise, returns the exception wrapped via
exSupplier
.
This is expected to typically used within a catch block, to throw a narrower scope:
try { … } catch (Throwable t) { throw AutoCloseables.closeAndWrap(t, SQLException.class, SQLException::new, closeable); }
See
Throwables.wrap(java.lang.Throwable, java.lang.Class, java.util.function.Function)
for details on howThreadDeath
andInterruptedException
are managed.- Parameters:
t0
- If notnull
, any new throwables will be combined viaThrowables.addSuppressed(java.lang.Throwable, java.lang.Throwable)
exClass
- Throwables of this class are returned directly.exSupplier
- Throwables that a not returned directly, and are notError
orRuntimeException
, are wrapped via this function, then returned.closeable
- The closeable to be closed- Returns:
null
whent0
isnull
and no new throwables, resulting throwable when is an instance ofexClass
, otherwise wrapped viaexSupplier
.- Throws:
Error
- When resulting throwable is anError
RuntimeException
- When resulting throwable is aRuntimeException
- See Also:
- When
-
closeAndWrap
public static <Ex extends Throwable> Ex closeAndWrap(Throwable t0, Class<? extends Ex> exClass, Function<? super Throwable, ? extends Ex> exSupplier, AutoCloseable... closeable) Closes all of the givenAutoCloseable
in order, catching allThrowable
. Wraps any resulting throwable, unless is an instance ofexClass
,Error
, orRuntimeException
.- When
null
, returnsnull
. - When is an instance of
exClass
, returns the exception. - When is
Error
orRuntimeException
, throws the exception directly. - Otherwise, returns the exception wrapped via
exSupplier
.
This is expected to typically used within a catch block, to throw a narrower scope:
try { … } catch (Throwable t) { throw AutoCloseables.closeAndWrap(t, SQLException.class, SQLException::new, closeable); }
See
Throwables.wrap(java.lang.Throwable, java.lang.Class, java.util.function.Function)
for details on howThreadDeath
andInterruptedException
are managed.- Parameters:
t0
- If notnull
, any new throwables will be combined viaThrowables.addSuppressed(java.lang.Throwable, java.lang.Throwable)
exClass
- Throwables of this class are returned directly.exSupplier
- Throwables that a not returned directly, and are notError
orRuntimeException
, are wrapped via this function, then returned.closeable
- The set of all closeables, which will be closed in order- Returns:
null
whent0
isnull
and no new throwables, resulting throwable when is an instance ofexClass
, otherwise wrapped viaexSupplier
.- Throws:
Error
- When resulting throwable is anError
RuntimeException
- When resulting throwable is aRuntimeException
- See Also:
- When
-
closeAndWrap
public static <Ex extends Throwable> Ex closeAndWrap(Throwable t0, Class<? extends Ex> exClass, Function<? super Throwable, ? extends Ex> exSupplier, Iterable<? extends AutoCloseable> closeable) Closes all of the givenAutoCloseable
in order, catching allThrowable
. Wraps any resulting throwable, unless is an instance ofexClass
,Error
, orRuntimeException
.- When
null
, returnsnull
. - When is an instance of
exClass
, returns the exception. - When is
Error
orRuntimeException
, throws the exception directly. - Otherwise, returns the exception wrapped via
exSupplier
.
This is expected to typically used within a catch block, to throw a narrower scope:
try { … } catch (Throwable t) { throw AutoCloseables.closeAndWrap(t, SQLException.class, SQLException::new, closeable); }
See
Throwables.wrap(java.lang.Throwable, java.lang.Class, java.util.function.Function)
for details on howThreadDeath
andInterruptedException
are managed.- Parameters:
t0
- If notnull
, any new throwables will be combined viaThrowables.addSuppressed(java.lang.Throwable, java.lang.Throwable)
exClass
- Throwables of this class are returned directly.exSupplier
- Throwables that a not returned directly, and are notError
orRuntimeException
, are wrapped via this function, then returned.closeable
- The set of all closeables, which will be closed in order- Returns:
null
whent0
isnull
and no new throwables, resulting throwable when is an instance ofexClass
, otherwise wrapped viaexSupplier
.- Throws:
Error
- When resulting throwable is anError
RuntimeException
- When resulting throwable is aRuntimeException
- See Also:
- When
-