public static class CommitOperations.MaybeIOE extends Object
maybeRethrow()
will throw any exception passed into the constructor, and be a no-op
if none was.
Why isn't a Java 8 optional used here? The main benefit would be that
maybeRethrow()
could be done as a map(), but because Java doesn't
allow checked exceptions in a map, the following code is invalid
exception.map((e) -> {throw e;}As a result, the code to work with exceptions would be almost as convoluted as the original.
Modifier and Type | Field and Description |
---|---|
static CommitOperations.MaybeIOE |
NONE |
Constructor and Description |
---|
MaybeIOE(IOException exception)
Construct with an exception.
|
Modifier and Type | Method and Description |
---|---|
IOException |
getException()
Get any exception.
|
boolean |
hasException()
Is there an exception in this class?
|
void |
maybeRethrow()
Rethrow any exception.
|
static CommitOperations.MaybeIOE |
of(IOException ex)
Get an instance based on the exception: either a value
or a reference to
NONE . |
String |
toString() |
public static final CommitOperations.MaybeIOE NONE
public MaybeIOE(IOException exception)
exception
- exceptionpublic IOException getException()
public boolean hasException()
public void maybeRethrow() throws IOException
IOException
- the exception field, if non-null.public static CommitOperations.MaybeIOE of(IOException ex)
NONE
.ex
- exceptionCopyright © 2008–2022 Apache Software Foundation. All rights reserved.