|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object sk.uniba.euromath.tools.ExceptionRegistry
public final class ExceptionRegistry
The exception registry. Each producer that runs in its own thread and fails with an exception should record this exception in this registry right before its thread is terminated.
When producer registers an exception and dies, an IOException
is thrown in piped read method (for example PipedInputStream.read()
when working with byte streams). This causes the receiver to fail, register
its exception and die, and so on. We can see that the very first (the oldest)
exception is the cause of all other exceptions, hence it is sufficient to
report just this 'cause'.
On the other hand, if receiver fails, registers the exception and terminates, this causes the producer to fail aswell, but we see that the first exception being reported is the real cause.
You should use the exception transferring mechanism like this:
final PipedExceptionReader consumer = new PipedExceptionReader();
final PipedWriter producer = new PipedWriter(reader);
new Thread() {
public void run() {
try {
// write something to the producer, throw an exception if something fails.
// this exception will be transparently rethrown in the consumer.
} catch(Throwable t) {
consumer.registry.registerException(t);
}
}
}
// you may now read from the consumer in this thread, any producer exceptions
// will be thrown in consumer's read methods.
Constructor Summary | |
---|---|
ExceptionRegistry()
|
Method Summary | |
---|---|
Throwable |
getCause()
Retrieves the cause (the oldest exception). |
List<Throwable> |
getRegistry()
Retrieves the registry, oldest exception occupying index 0. |
void |
registerException(Throwable ex)
Records an exception. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ExceptionRegistry()
Method Detail |
---|
public void registerException(Throwable ex)
ex
- exception to record.public List<Throwable> getRegistry()
null
.public Throwable getCause()
null
if no
exception was recorded.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |