Skip to content
Snippets Groups Projects
Commit 1c487a5c authored by brinn's avatar brinn
Browse files

change: make StoringUncaughtExceptionHandler.checkAndRethrowException() throw...

change: make StoringUncaughtExceptionHandler.checkAndRethrowException() throw the exception itself, rather than a new one
add: method checkAndRetrhowExceptionWrapIfNecessary() that wraps checked exceptions, but otherwise works the same way

SVN: 7045
parent e50b6692
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,8 @@ package ch.systemsx.cisd.common.test;
import java.lang.Thread.UncaughtExceptionHandler;
import ch.systemsx.cisd.common.exceptions.CheckedExceptionTunnel;
/**
* An exception handler that stores the first occurring exception for later investigation. Needs to
* be activated by
......@@ -78,15 +80,26 @@ public final class StoringUncaughtExceptionHandler implements UncaughtExceptionH
}
/**
* Checks whether an exception or error has occurred and, if yes, throws a new
* {@link RuntimeException} with the caught exception as cause in the current thread.
* Checks whether an exception or error has occurred and, if yes, re-throws it in the current
* thread, wrapping it into a {@link CheckedExceptionTunnel} if necessary.
*/
public void checkAndRethrowExceptionWrapIfNecessary()
{
if (hasExceptionOccurred())
{
throw CheckedExceptionTunnel.wrapIfNecessary(getThrowable());
}
}
/**
* Checks whether an exception or error has occurred and, if yes, re-throws it in the current
* thread.
*/
public void checkAndRethrowException()
public void checkAndRethrowException() throws Throwable
{
if (hasExceptionOccurred())
{
throw new RuntimeException(String.format("An exception occurred in thread %s.",
getThreadName()), getThrowable());
throw getThrowable();
}
}
......
......@@ -219,7 +219,7 @@ public class CopyActivityMonitorTest
}
@AfterMethod
public void checkException()
public void checkException() throws Throwable
{
exceptionHandler.checkAndRethrowException();
}
......
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