public class TaggedIOException extends IOExceptionWithCause
IOException decorator that adds a serializable tag to the
wrapped exception. Both the tag and the original exception can be used
to determine further processing when this exception is caught.| Modifier and Type | Field and Description |
|---|---|
private static long |
serialVersionUID
Generated serial version UID.
|
private java.io.Serializable |
tag
The tag of this exception.
|
| Constructor and Description |
|---|
TaggedIOException(java.io.IOException original,
java.io.Serializable tag)
Creates a tagged wrapper for the given exception.
|
| Modifier and Type | Method and Description |
|---|---|
java.io.IOException |
getCause()
Returns the wrapped exception.
|
java.io.Serializable |
getTag()
Returns the serializable tag object.
|
static boolean |
isTaggedWith(java.lang.Throwable throwable,
java.lang.Object tag)
Checks whether the given throwable is tagged with the given tag.
|
static void |
throwCauseIfTaggedWith(java.lang.Throwable throwable,
java.lang.Object tag)
Throws the original
IOException if the given throwable is
a TaggedIOException decorator the given tag. |
private static final long serialVersionUID
private final java.io.Serializable tag
public TaggedIOException(java.io.IOException original,
java.io.Serializable tag)
original - the exception to be taggedtag - tag of this exceptionpublic static boolean isTaggedWith(java.lang.Throwable throwable,
java.lang.Object tag)
This check can only succeed if the throwable is a
TaggedIOException and the tag is Serializable, but
the argument types are intentionally more generic to make it easier
to use this method without type casts.
A typical use for this method is in a catch block to
determine how a caught exception should be handled:
Serializable tag = ...;
try {
...;
} catch (Throwable t) {
if (TaggedIOExcepton.isTaggedWith(t, tag)) {
// special processing for tagged exception
} else {
// handling of other kinds of exceptions
}
}
throwable - The Throwable object to checktag - tag objecttrue if the throwable has the specified tag,
otherwise falsepublic static void throwCauseIfTaggedWith(java.lang.Throwable throwable,
java.lang.Object tag)
throws java.io.IOException
IOException if the given throwable is
a TaggedIOException decorator the given tag. Does nothing
if the given throwable is of a different type or if it is tagged
with some other tag.
This method is typically used in a catch block to
selectively rethrow tagged exceptions.
Serializable tag = ...;
try {
...;
} catch (Throwable t) {
TaggedIOExcepton.throwCauseIfTagged(t, tag);
// handle other kinds of exceptions
}
throwable - an exceptiontag - tag objectjava.io.IOException - original exception from the tagged decorator, if anypublic java.io.Serializable getTag()
public java.io.IOException getCause()
Throwable.getCause() method is the narrower return type.getCause in class java.lang.ThrowableCopyright (c) 2002-2016 Apache Software Foundation