public class SequentialIOException extends IOException implements Cloneable
IOExceptions 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.
| Modifier and Type | Field and Description |
|---|---|
private int |
index |
(package private) static Comparator<SequentialIOException> |
INDEX_COMP
Compares two chainable I/O exceptions in descending order of their
appearance.
|
(package private) int |
maxIndex |
private static int |
maxPrintExceptions |
private SequentialIOException |
predecessor
The tail of this exception chain.
|
private int |
priority |
(package private) static Comparator<SequentialIOException> |
PRIORITY_COMP
Compares two chainable I/O exceptions in descending order of their
priority.
|
private static long |
serialVersionUID |
| 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() |
private int |
getNumExceptions() |
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.
|
private SequentialIOException |
insert(SequentialIOException element,
Comparator<SequentialIOException> cmp) |
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) |
private void |
setPredecessor(SequentialIOException predecessor) |
private SequentialIOException |
sort(Comparator<SequentialIOException> cmp) |
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, toStringprivate static final long serialVersionUID
private static int maxPrintExceptions
static final Comparator<SequentialIOException> PRIORITY_COMP
static final Comparator<SequentialIOException> INDEX_COMP
private SequentialIOException predecessor
this if the predecessor hasn't been
initPredecessor(SequentialIOException) initialized yet or
null if there are no more exceptions in this chain.private final int priority
private int index
int maxIndex
public SequentialIOException()
public SequentialIOException(String message)
public SequentialIOException(Throwable cause)
public SequentialIOException(int priority)
public SequentialIOException(String message, int priority)
public SequentialIOException(Throwable cause, int priority)
public SequentialIOException(String message, 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 clone()
public SequentialIOException initCause(Throwable cause)
public final SequentialIOException initPredecessor(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.private void setPredecessor(SequentialIOException predecessor)
public final SequentialIOException getPredecessor()
null if no predecessing exception exists or this property
hasn't been
initialized yet.public final int getPriority()
public SequentialIOException sortPriority()
public SequentialIOException sortAppearance()
private SequentialIOException sort(Comparator<SequentialIOException> cmp)
private SequentialIOException insert(SequentialIOException element, Comparator<SequentialIOException> cmp)
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 Throwablepublic 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.
private int getNumExceptions()
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 Throwablepublic 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 int getMaxPrintExceptions()
public static void setMaxPrintExceptions(int maxPrintExcepions)
Copyright © 2005-2011 Schlichtherle IT Services. All Rights Reserved.