@ThreadSafe public class SequentialIOException extends IOException implements Cloneable
IOException
s which have
not caused each other.
This class supports chaining I/O exceptions for reasons other than causes (which is a functionality already provided by J2SE 1.4 and later). A chainable I/O exception can be used to implement an algorithm which must be able to continue with some work although one or more I/O exceptions have occured.
For example, when looping through a list of files, an algorithm might
encounter an I/O exception when processing a file element in the list.
However, it may still be required to process the remaining files in the list
before actually throwing the corresponding I/O exception.
Hence, whenever this algorithm encounters an I/O exception, it would catch
the I/O exception, create a chainable I/O exception for it and continue
processing the remainder of the list.
Finally, at the end of the algorithm, if any I/O exceptions
have occured, the chainable I/O exception would get sorted according to
priority (see getPriority()
and sortPriority()
) and
finally thrown.
This would allow a client application to filter the I/O exceptions by
priority with a simple try-catch statement, ensuring that no other
exception of higher priority is in the catched exception chain.
This class is thread-safe.
Constructor and Description |
---|
SequentialIOException() |
SequentialIOException(int priority) |
SequentialIOException(String message) |
SequentialIOException(String message,
int priority) |
SequentialIOException(String message,
Throwable cause) |
SequentialIOException(String message,
Throwable cause,
int priority)
Constructs a new chainable I/O exception with the given
message , cause and priority . |
SequentialIOException(Throwable cause) |
SequentialIOException(Throwable cause,
int priority) |
Modifier and Type | Method and Description |
---|---|
SequentialIOException |
clone()
Returns a shallow clone of this exception.
|
static int |
getMaxPrintExceptions() |
SequentialIOException |
getPredecessor()
Returns the exception chain represented by the predecessing exception,
or
null if no predecessing exception exists or this property
hasn't been
initialized yet. |
int |
getPriority()
Returns the priority of this exception.
|
SequentialIOException |
initCause(Throwable cause) |
SequentialIOException |
initPredecessor(SequentialIOException predecessor)
Initializes the predecessor of this chainable exception to
the given object.
|
void |
printStackTrace(PrintStream s)
Prints up to
getMaxPrintExceptions() exceptions in this
chain to the provided PrintStream . |
void |
printStackTrace(PrintStream s,
int maxExceptions)
Prints up to
maxExceptions() exceptions in this
chain to the provided PrintStream . |
void |
printStackTrace(PrintWriter s)
Prints up to
getMaxPrintExceptions() exceptions in this
chain to the provided PrintStream . |
void |
printStackTrace(PrintWriter s,
int maxExceptions)
Prints up to
maxExceptions() exceptions in this
chain to the provided PrintStream . |
static void |
setMaxPrintExceptions(int maxPrintExcepions) |
SequentialIOException |
sortAppearance()
Sorts the elements of this exception chain in descending order
of their appearance.
|
SequentialIOException |
sortPriority()
Sorts the elements of this exception chain in descending order
of their priority.
|
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, printStackTrace, setStackTrace, toString
public SequentialIOException()
public SequentialIOException(int priority)
public SequentialIOException(@CheckForNull String message)
public SequentialIOException(@CheckForNull String message, int priority)
public SequentialIOException(@CheckForNull String message, @CheckForNull Throwable cause)
public SequentialIOException(@CheckForNull String message, @CheckForNull Throwable cause, int priority)
message
, cause
and priority
.
The predecessor of this exception remains unknown until initiliazed
by calling the method initPredecessor(SequentialIOException)
.message
- The message for this exception.cause
- The cause exception.
A null
value is permitted, and indicates that the cause
for this exception is nonexistent.priority
- The priority of this exception to be used for
priority sorting
.public SequentialIOException(@CheckForNull Throwable cause)
public SequentialIOException(@CheckForNull Throwable cause, int priority)
public SequentialIOException clone()
public static int getMaxPrintExceptions()
@Nullable public final SequentialIOException getPredecessor()
null
if no predecessing exception exists or this property
hasn't been
initialized
yet.public final int getPriority()
public SequentialIOException initCause(Throwable cause)
public SequentialIOException initPredecessor(@CheckForNull SequentialIOException predecessor)
predecessor
- An exception that happened before and is
not the cause for this exception!
Must be null
to indicate that a predecessor does not
exist.IllegalStateException
- If the predecessor has already been set.IllegalArgumentException
- If the given predecessor
is
this instance or has not been initialized with a predecessor
itself.public void printStackTrace(PrintStream s)
getMaxPrintExceptions()
exceptions in this
chain to the provided PrintStream
.
Exceptions are printed in ascending order of this chain. If this chain has not been sorted, this results in the exceptions being printed in order of their appearance.
If more exceptions are in this chain than are allowed to be printed, then the printed message starts with a line indicating the number of exceptions which have been omitted from the beginning of this chain. Thus, this exception is always printed as the last exception in the list.
printStackTrace
in class Throwable
public void printStackTrace(PrintStream s, int maxExceptions)
maxExceptions()
exceptions in this
chain to the provided PrintStream
.
Exceptions are printed in ascending order of this chain. If this chain has not been sorted, this results in the exceptions being printed in order of their appearance.
If more exceptions are in this chain than are allowed to be printed, then the printed message starts with a line indicating the number of exceptions which have been omitted from the beginning of this chain. Thus, this exception is always printed as the last exception in the list.
public void printStackTrace(PrintWriter s)
getMaxPrintExceptions()
exceptions in this
chain to the provided PrintStream
.
Exceptions are printed in ascending order of this chain. If this chain has not been sorted, this results in the exceptions being printed in order of their appearance.
If more exceptions are in this chain than are allowed to be printed, then the printed message starts with a line indicating the number of exceptions which have been omitted from the beginning of this chain. Thus, this exception is always printed as the last exception in the list.
printStackTrace
in class Throwable
public void printStackTrace(PrintWriter s, int maxExceptions)
maxExceptions()
exceptions in this
chain to the provided PrintStream
.
Exceptions are printed in ascending order of this chain. If this chain has not been sorted, this results in the exceptions being printed in order of their appearance.
If more exceptions are in this chain than are allowed to be printed, then the printed message starts with a line indicating the number of exceptions which have been omitted from the beginning of this chain. Thus, this exception is always printed as the last exception in the list.
public static void setMaxPrintExceptions(int maxPrintExcepions)
public SequentialIOException sortAppearance()
public SequentialIOException sortPriority()
Copyright © 2005–2018 Schlichtherle IT Services. All rights reserved.