diff --git a/common/sourceTest/java/ch/systemsx/cisd/common/test/StoringUncaughtExceptionHandler.java b/common/sourceTest/java/ch/systemsx/cisd/common/test/StoringUncaughtExceptionHandler.java index 12a25e4cbdb93ab21c12d49768a65eaafc4cbed0..b698d04d1f78701e526017274c99a5c36af3a05f 100644 --- a/common/sourceTest/java/ch/systemsx/cisd/common/test/StoringUncaughtExceptionHandler.java +++ b/common/sourceTest/java/ch/systemsx/cisd/common/test/StoringUncaughtExceptionHandler.java @@ -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(); } } diff --git a/datamover/sourceTest/java/ch/systemsx/cisd/datamover/filesystem/remote/CopyActivityMonitorTest.java b/datamover/sourceTest/java/ch/systemsx/cisd/datamover/filesystem/remote/CopyActivityMonitorTest.java index 44526cfc2e4c739a53fc7ec505a0ffd007e189e0..12de2e66f869431d9273fcd15ceade84fdb539d0 100644 --- a/datamover/sourceTest/java/ch/systemsx/cisd/datamover/filesystem/remote/CopyActivityMonitorTest.java +++ b/datamover/sourceTest/java/ch/systemsx/cisd/datamover/filesystem/remote/CopyActivityMonitorTest.java @@ -219,7 +219,7 @@ public class CopyActivityMonitorTest } @AfterMethod - public void checkException() + public void checkException() throws Throwable { exceptionHandler.checkAndRethrowException(); }