Skip to content
Snippets Groups Projects
Commit 692f43b0 authored by brinn's avatar brinn
Browse files

add: unchecked TimeoutException and wrapping of InterruptedException into TimeoutException

SVN: 6497
parent 66614591
No related branches found
No related tags found
No related merge requests found
...@@ -38,10 +38,28 @@ public final class CheckedExceptionTunnel extends RuntimeException ...@@ -38,10 +38,28 @@ public final class CheckedExceptionTunnel extends RuntimeException
assert (checkedException != null && checkedException instanceof RuntimeException) == false; assert (checkedException != null && checkedException instanceof RuntimeException) == false;
} }
/**
* Convenience wrapper for {@link #wrapIfNecessary(Exception)}. If <var>throwable</var> is an
* {@link Error}, this method will not return but the error will be thrown.
*
* @param throwable The exception to represent by the return value.
* @return A {@link RuntimeException} representing the <var>throwable</var>.
* @throws Error If <var>throwable</var> is an {@link Error}.
*/
public final static RuntimeException wrapIfNecessary(final Throwable throwable) throws Error
{
if (throwable instanceof Error)
{
throw (Error) throwable;
}
return wrapIfNecessary((Exception) throwable);
}
/** /**
* Returns a {@link RuntimeException} from an <var>exception</var>. If <var>exception</var> is * Returns a {@link RuntimeException} from an <var>exception</var>. If <var>exception</var> is
* already a {@link RuntimeException}, itself is returned, otherwise a * already a {@link RuntimeException}, itself is returned, otherwise an appropriate unchecked
* {@link CheckedExceptionTunnel} with <var>exception</var> as checked exception argument. * equivalent. If no unchecked equivalent exists, a {@link CheckedExceptionTunnel} is returned
* with <var>exception</var> 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>.
...@@ -54,7 +72,11 @@ public final class CheckedExceptionTunnel extends RuntimeException ...@@ -54,7 +72,11 @@ public final class CheckedExceptionTunnel extends RuntimeException
} }
if (exception instanceof InterruptedException) if (exception instanceof InterruptedException)
{ {
return new StopException(exception); return new StopException((InterruptedException) exception);
}
if (exception instanceof java.util.concurrent.TimeoutException)
{
return new TimeoutException((java.util.concurrent.TimeoutException) exception);
} }
return new CheckedExceptionTunnel(exception); return new CheckedExceptionTunnel(exception);
} }
......
...@@ -17,7 +17,8 @@ ...@@ -17,7 +17,8 @@
package ch.systemsx.cisd.common.exceptions; package ch.systemsx.cisd.common.exceptions;
/** /**
* Exception that signals that whoever gets it should stop its current work. * Exception that signals that whoever gets it should stop its current work. This is an unchecked
* equivalent to an {@link InterruptedException}.
* <p> * <p>
* This is usually triggered by interrupting the thread that the work package is processed in and * This is usually triggered by interrupting the thread that the work package is processed in and
* regularly checking with {@link #check()}. * regularly checking with {@link #check()}.
...@@ -35,7 +36,7 @@ public final class StopException extends RuntimeException ...@@ -35,7 +36,7 @@ public final class StopException extends RuntimeException
super(); super();
} }
public StopException(final Throwable cause) public StopException(InterruptedException cause)
{ {
super(cause); super(cause);
} }
......
/*
* Copyright 2008 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package ch.systemsx.cisd.common.exceptions;
/**
* Exception thrown when a blocking operation times out. This is an unchecked equivalent of
* {@link java.util.concurrent.TimeoutException}, i.e. it is derived from {@link RuntimeException}.
*
* @author Bernd Rinn
*/
public class TimeoutException extends RuntimeException
{
private static final long serialVersionUID = 1L;
public TimeoutException()
{
super();
}
public TimeoutException(String msg)
{
super(msg);
}
public TimeoutException(java.util.concurrent.TimeoutException cause)
{
super(cause);
}
}
\ No newline at end of file
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