From 1c487a5c0ad6c3681ed4020f2cd6d7d830ddb35b Mon Sep 17 00:00:00 2001 From: brinn <brinn> Date: Fri, 4 Jul 2008 18:13:49 +0000 Subject: [PATCH] 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 --- .../test/StoringUncaughtExceptionHandler.java | 23 +++++++++++++++---- .../remote/CopyActivityMonitorTest.java | 2 +- 2 files changed, 19 insertions(+), 6 deletions(-) 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 12a25e4cbdb..b698d04d1f7 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 44526cfc2e4..12de2e66f86 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(); } -- GitLab