public interface CloseableScope extends AutoCloseable
AutoCloseable
that throws only unchecked exceptions.
Modifier and Type | Method and Description |
---|---|
default CloseableScope |
andFinally(Runnable action)
Creates extended CloseableScope that additionally runs specified action regardless of exceptions.
|
default CloseableScope |
andThen(Runnable action)
Creates extended CloseableScope that additionally runs specified action unless exception is thrown.
|
void |
close()
Closes this scope or other closeable resource.
|
void close()
AutoCloseable.close()
that throws only unchecked exceptions.
close
in interface AutoCloseable
default CloseableScope andThen(Runnable action)
CloseableScope
that additionally runs specified action
unless exception is thrown. This is useful for quickly creating outer scopes that add extra operations to some inner scope. If close()
throws, action
does not run.
action
- the operation to perform after close()
is called
CloseableScope
that, when closed, first closes this CloseableScope
and then executes action
NullPointerException
- if action
is null
andFinally(Runnable)
default CloseableScope andFinally(Runnable action)
CloseableScope
that additionally runs specified action
regardless of exceptions. This is useful for quickly creating outer scopes that add extra operations to some inner scope. If close()
throws, action
runs anyway as if in try-with-resources block. If both close()
} and action
throw, the exception from action
is added to suppressed exception list by calling Throwable.addSuppressed(Throwable)
.
action
- the operation to perform after close()
is called
CloseableScope
that, when closed, first closes this CloseableScope
and then executes action
NullPointerException
- if action
is null
andThen(Runnable)
Copyright © 2017–2020 Robert Važan. All rights reserved.