From e66850c9917f6b87d6f6e32deab36dc8cef45f49 Mon Sep 17 00:00:00 2001 From: brinn <brinn> Date: Sat, 6 Aug 2011 09:09:23 +0000 Subject: [PATCH] add: option to create IOExceptionUnchecked from a non-IOException and from a message SVN: 22372 --- .../base/exceptions/IOExceptionUnchecked.java | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/base/source/java/ch/systemsx/cisd/base/exceptions/IOExceptionUnchecked.java b/base/source/java/ch/systemsx/cisd/base/exceptions/IOExceptionUnchecked.java index c3a788c6392..caa7b39f031 100644 --- a/base/source/java/ch/systemsx/cisd/base/exceptions/IOExceptionUnchecked.java +++ b/base/source/java/ch/systemsx/cisd/base/exceptions/IOExceptionUnchecked.java @@ -19,8 +19,8 @@ package ch.systemsx.cisd.base.exceptions; import java.io.IOException; /** - * A {@link CheckedExceptionTunnel} for an {@link IOException}. - * + * A {@link CheckedExceptionTunnel} for an {@link IOException}. + * * @author Bernd Rinn */ public class IOExceptionUnchecked extends CheckedExceptionTunnel @@ -28,7 +28,7 @@ public class IOExceptionUnchecked extends CheckedExceptionTunnel private static final long serialVersionUID = 1L; /** - * Returns an unchecked exception from a <var>checkedException</var>. + * Returns an <code>IOExceptionUnchecked</code> from a <code>IOException</code>. * * @param checkedException The checked exception to tunnel. */ @@ -39,6 +39,39 @@ public class IOExceptionUnchecked extends CheckedExceptionTunnel assert checkedException != null; } + /** + * Returns an <code>IOExceptionUnchecked</code> from a newly created <code>IOException</code> + * with given <var>msg</var>. + * + * @param msg The checked exception to tunnel. + */ + public IOExceptionUnchecked(final String msg) + { + this(new IOException(msg)); + } + + private static IOException createIOException(final Throwable throwable) + { + final IOException ioe = + new IOException(throwable.getClass().getSimpleName() + ": " + + throwable.getMessage()); + ioe.initCause(throwable); + return ioe; + } + + /** + * Returns an <code>IOExceptionUnchecked</code> from newly created <code>IOException</code> with + * given <var>throwable</var> as its cause. + * + * @param throwable The throwable to use the cause of the created <code>IOException</code>. + */ + public IOExceptionUnchecked(final Throwable throwable) + { + super(createIOException(throwable)); + + assert throwable != null; + } + @Override public IOException getCause() { -- GitLab