public class TaggedWriter extends ProxyWriter
TaggedIOException
class to wrap all thrown
IOException
s. See below for an example of using this class.
TaggedReader reader = new TaggedReader(...); try { // Processing that may throw an IOException either from this reader // or from some other IO activity like temporary files, etc. writeToWriter(writer); } catch (IOException e) { if (writer.isCauseOf(e)) { // The exception was caused by this writer. // Use e.getCause() to get the original exception. } else { // The exception was caused by something else. } }
Alternatively, the throwIfCauseOf(Exception)
method can be
used to let higher levels of code handle the exception caused by this
writer while other processing errors are being taken care of at this
lower level.
TaggedWriter writer = new TaggedWriter(...); try { writeToWriter(writer); } catch (IOException e) { writer.throwIfCauseOf(e); // ... or process the exception that was caused by something else }
TaggedIOException
Constructor and Description |
---|
TaggedWriter(Writer proxy)
Creates a tagging decorator for the given writer.
|
Modifier and Type | Method and Description |
---|---|
boolean |
isCauseOf(Exception exception)
Tests if the given exception was caused by this writer.
|
void |
throwIfCauseOf(Exception exception)
Re-throws the original exception thrown by this writer.
|
public TaggedWriter(Writer proxy)
proxy
- writer to be decoratedpublic boolean isCauseOf(Exception exception)
exception
- an exceptiontrue
if the exception was thrown by this writer,
false
otherwisepublic void throwIfCauseOf(Exception exception) throws IOException
TaggedIOException
wrapper created by this decorator, and then unwraps and throws the
original wrapped exception. Returns normally if the exception was
not thrown by this writer.exception
- an exceptionIOException
- original exception, if any, thrown by this writerJas4pp 1.5 © Java Analysis Studio for Particle Physics