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