Skip to content
Snippets Groups Projects
Commit 2d6447d1 authored by ribeaudc's avatar ribeaudc
Browse files

add: - 'CheckedExceptionTunnel.unwrapIfNecessary'.

SVN: 4456
parent 371501ab
No related branches found
No related tags found
No related merge requests found
...@@ -31,7 +31,7 @@ public final class CheckedExceptionTunnel extends RuntimeException ...@@ -31,7 +31,7 @@ public final class CheckedExceptionTunnel extends RuntimeException
* *
* @param checkedException The checked exception to tunnel. * @param checkedException The checked exception to tunnel.
*/ */
public CheckedExceptionTunnel(Exception checkedException) public CheckedExceptionTunnel(final Exception checkedException)
{ {
super(checkedException); super(checkedException);
...@@ -40,14 +40,15 @@ public final class CheckedExceptionTunnel extends RuntimeException ...@@ -40,14 +40,15 @@ public final class CheckedExceptionTunnel extends RuntimeException
/** /**
* Returns a {@link RuntimeException} from an <var>exception</var>. If <var>exception</var> is already a * Returns a {@link RuntimeException} from an <var>exception</var>. If <var>exception</var> is already a
* {@link RuntimeException}, itself is returned, otherwise a {@link CheckedExceptionTunnel} with * {@link RuntimeException}, itself is returned, otherwise a {@link CheckedExceptionTunnel} with <var>exception</var>
* <var>exception</var> as checked exception argument. * as checked exception argument.
* *
* @param exception The exception to represent by the return value. * @param exception The exception to represent by the return value.
* @return A {@link RuntimeException} representing the <var>exception</var>. * @return A {@link RuntimeException} representing the <var>exception</var>.
*/ */
public static RuntimeException wrapIfNecessary(Exception exception) public final static RuntimeException wrapIfNecessary(final Exception exception)
{ {
assert exception != null : "Unspecified exception.";
if (exception instanceof RuntimeException) if (exception instanceof RuntimeException)
{ {
return (RuntimeException) exception; return (RuntimeException) exception;
...@@ -57,4 +58,21 @@ public final class CheckedExceptionTunnel extends RuntimeException ...@@ -57,4 +58,21 @@ public final class CheckedExceptionTunnel extends RuntimeException
} }
} }
/**
* Returns the original exception before being wrapped, if the exception has been wrapped, or <var>exception</var>
* otherwise.
*/
public final static Exception unwrapIfNecessary(final RuntimeException exception)
{
assert exception != null : "Unspecified exception.";
if (exception instanceof CheckedExceptionTunnel)
{
// We are sur that the wrapped exception is an 'Exception'.
return (Exception) exception.getCause();
} else
{
return exception;
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment