diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleRetryExceptionHandler.java b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleRetryExceptionHandler.java index 7e4ecb11e..27c5c5955 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleRetryExceptionHandler.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleRetryExceptionHandler.java @@ -52,7 +52,7 @@ public class SimpleRetryExceptionHandler extends RetryListenerSupport implements * @see org.springframework.batch.repeat.exception.handler.ExceptionHandler#handleException(org.springframework.batch.repeat.RepeatContext, * java.lang.Throwable) */ - public void handleException(RepeatContext context, Throwable throwable) throws RuntimeException { + public void handleException(RepeatContext context, Throwable throwable) throws Throwable { // Only bother to check the delegate exception handler if we know that // retry is exhausted if (context.hasAttribute(EXHAUSTED)) { diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleRetryExceptionHandlerTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleRetryExceptionHandlerTests.java index d4c4254b5..42d5406ab 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleRetryExceptionHandlerTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/item/SimpleRetryExceptionHandlerTests.java @@ -54,7 +54,7 @@ public class SimpleRetryExceptionHandlerTests extends TestCase { * Test method for * {@link org.springframework.batch.core.step.item.SimpleRetryExceptionHandler#handleException(org.springframework.batch.repeat.RepeatContext, java.lang.Throwable)}. */ - public void testRethrowWhenRetryExhausted() { + public void testRethrowWhenRetryExhausted() throws Throwable { RetryPolicy retryPolicy = new NeverRetryPolicy(); RuntimeException ex = new RuntimeException("foo"); @@ -79,7 +79,7 @@ public class SimpleRetryExceptionHandlerTests extends TestCase { * Test method for * {@link org.springframework.batch.core.step.item.SimpleRetryExceptionHandler#handleException(org.springframework.batch.repeat.RepeatContext, java.lang.Throwable)}. */ - public void testNoRethrowWhenRetryNotExhausted() { + public void testNoRethrowWhenRetryNotExhausted() throws Throwable { RetryPolicy retryPolicy = new AlwaysRetryPolicy(); RuntimeException ex = new RuntimeException("foo"); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/CompositeExceptionHandler.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/CompositeExceptionHandler.java index a0f4c5be0..3c76ebf95 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/CompositeExceptionHandler.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/CompositeExceptionHandler.java @@ -39,7 +39,7 @@ public class CompositeExceptionHandler implements ExceptionHandler { * * @see ExceptionHandler#handleException(RepeatContext, Throwable) */ - public void handleException(RepeatContext context, Throwable throwable) throws RuntimeException { + public void handleException(RepeatContext context, Throwable throwable) throws Throwable { for (int i = 0; i < handlers.length; i++) { ExceptionHandler handler = handlers[i]; handler.handleException(context, throwable); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/DefaultExceptionHandler.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/DefaultExceptionHandler.java index 207cd258f..b637f9359 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/DefaultExceptionHandler.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/DefaultExceptionHandler.java @@ -34,7 +34,7 @@ public class DefaultExceptionHandler implements ExceptionHandler { * @see org.springframework.batch.repeat.exception.ExceptionHandler#handleException(RepeatContext, * Throwable) */ - public void handleException(RepeatContext context, Throwable throwable) throws RuntimeException { + public void handleException(RepeatContext context, Throwable throwable) throws Throwable { rethrow(throwable); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/ExceptionHandler.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/ExceptionHandler.java index cdb672e73..86f96916a 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/ExceptionHandler.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/ExceptionHandler.java @@ -20,34 +20,29 @@ import org.springframework.batch.repeat.CompletionPolicy; import org.springframework.batch.repeat.RepeatContext; /** - * Handler to allow strategies for rethrowing exceptions. Normally a + * Handler to allow strategies for re-throwing exceptions. Normally a * {@link CompletionPolicy} will be used to decide whether to end a batch when * there is no exception, and the {@link ExceptionHandler} is used to signal an * abnormal ending - an abnormal ending would result in an * {@link ExceptionHandler} throwing an exception. The caller will catch and - * rethrow it if necessary. + * re-throw it if necessary. * * @author Dave Syer + * @author Robert Kasanicky * */ public interface ExceptionHandler { /** - * Deal with a Throwable during a batch. The input might be - * RuntimeException or other unchecked exceptions. + * Deal with a Throwable during a batch - decide whether it should be + * re-thrown in the first place. * - * @param context - * the current {@link RepeatContext}. Can be used to store state - * (via attributes), for example to count the number of - * occurrences of a particular exception type and implement a - * threshold policy. - * @param throwable - * an exception. - * @throws RuntimeException - * implementations must wrap and rethrow other Throwables - * appropriately. + * @param context the current {@link RepeatContext}. Can be used to store + * state (via attributes), for example to count the number of occurrences of + * a particular exception type and implement a threshold policy. + * @param throwable an exception. + * @throws Throwable implementations are free to re-throw the exception */ - void handleException(RepeatContext context, Throwable throwable) - throws RuntimeException; + void handleException(RepeatContext context, Throwable throwable) throws Throwable; } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandler.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandler.java index 4feb8f725..4838c4917 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandler.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandler.java @@ -79,7 +79,7 @@ public class LogOrRethrowExceptionHandler implements ExceptionHandler { * * @see {@link ExceptionHandler#handleException(RepeatContext, Throwable)} */ - public void handleException(RepeatContext context, Throwable throwable) throws RuntimeException { + public void handleException(RepeatContext context, Throwable throwable) throws Throwable { Object key = exceptionClassifier.classify(throwable); if (ERROR.equals(key)) { diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/RethrowOnThresholdExceptionHandler.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/RethrowOnThresholdExceptionHandler.java index 187a9f17f..318ff78be 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/RethrowOnThresholdExceptionHandler.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/RethrowOnThresholdExceptionHandler.java @@ -107,15 +107,15 @@ public class RethrowOnThresholdExceptionHandler implements ExceptionHandler { } /** - * Classify the throwables and decide whether to rethrow based on the + * Classify the throwables and decide whether to re-throw based on the * result. The context is used to accumulate the number of exceptions of the * same type according to the classifier. * - * @throws Exception + * @throws Throwable * @see {@link ExceptionHandler#handleException(RepeatContext, Throwable)} */ public void handleException(RepeatContext context, Throwable throwable) - throws RuntimeException { + throws Throwable { Object key = exceptionClassifier.classify(throwable); RepeatContextCounter counter = getCounter(context, key); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/SimpleLimitExceptionHandler.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/SimpleLimitExceptionHandler.java index 9f45bbbec..79985c403 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/SimpleLimitExceptionHandler.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/repeat/exception/SimpleLimitExceptionHandler.java @@ -105,7 +105,7 @@ public class SimpleLimitExceptionHandler implements ExceptionHandler { * @see org.springframework.batch.repeat.exception.ExceptionHandler#handleException(org.springframework.batch.repeat.RepeatContext, * Throwable) */ - public void handleException(RepeatContext context, Throwable throwable) throws RuntimeException { + public void handleException(RepeatContext context, Throwable throwable) throws Throwable { delegate.handleException(context, throwable); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/CompositeExceptionHandlerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/CompositeExceptionHandlerTests.java index f35c022ab..2418b8466 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/CompositeExceptionHandlerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/CompositeExceptionHandlerTests.java @@ -29,7 +29,7 @@ public class CompositeExceptionHandlerTests extends TestCase { private CompositeExceptionHandler handler = new CompositeExceptionHandler(); - public void testNewHandler() throws Exception { + public void testNewHandler() throws Throwable { try { handler.handleException(null, new RuntimeException()); } @@ -38,7 +38,7 @@ public class CompositeExceptionHandlerTests extends TestCase { } } - public void testDelegation() throws Exception { + public void testDelegation() throws Throwable { final List list = new ArrayList(); handler.setHandlers(new ExceptionHandler[] { new ExceptionHandler() { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/DefaultExceptionHandlerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/DefaultExceptionHandlerTests.java index 30ea5905e..b0ba14886 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/DefaultExceptionHandlerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/DefaultExceptionHandlerTests.java @@ -25,7 +25,7 @@ public class DefaultExceptionHandlerTests extends TestCase { private DefaultExceptionHandler handler = new DefaultExceptionHandler(); private RepeatContext context = null; - public void testRuntimeException() throws Exception { + public void testRuntimeException() throws Throwable { try { handler.handleException(context, new RuntimeException("Foo")); fail("Expected RuntimeException"); @@ -34,7 +34,7 @@ public class DefaultExceptionHandlerTests extends TestCase { } } - public void testError() throws Exception { + public void testError() throws Throwable { try { handler.handleException(context, new Error("Foo")); fail("Expected Error"); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandlerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandlerTests.java index b0bb3ba4e..b7f2c6193 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandlerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandlerTests.java @@ -43,7 +43,7 @@ public class LogOrRethrowExceptionHandlerTests extends TestCase { logger.addAppender(new WriterAppender(new SimpleLayout(), writer)); } - public void testRuntimeException() throws Exception { + public void testRuntimeException() throws Throwable { try { handler.handleException(context, new RuntimeException("Foo")); fail("Expected RuntimeException"); @@ -52,7 +52,7 @@ public class LogOrRethrowExceptionHandlerTests extends TestCase { } } - public void testError() throws Exception { + public void testError() throws Throwable { try { handler.handleException(context, new Error("Foo")); fail("Expected Error"); @@ -61,7 +61,7 @@ public class LogOrRethrowExceptionHandlerTests extends TestCase { } } - public void testNotRethrownErrorLevel() throws Exception { + public void testNotRethrownErrorLevel() throws Throwable { handler.setExceptionClassifier(new ExceptionClassifierSupport() { public Object classify(Throwable throwable) { return LogOrRethrowExceptionHandler.ERROR; @@ -72,7 +72,7 @@ public class LogOrRethrowExceptionHandlerTests extends TestCase { assertNotNull(writer.toString()); } - public void testNotRethrownWarnLevel() throws Exception { + public void testNotRethrownWarnLevel() throws Throwable { handler.setExceptionClassifier(new ExceptionClassifierSupport() { public Object classify(Throwable throwable) { return LogOrRethrowExceptionHandler.WARN; @@ -83,7 +83,7 @@ public class LogOrRethrowExceptionHandlerTests extends TestCase { assertNotNull(writer.toString()); } - public void testNotRethrownDebugLevel() throws Exception { + public void testNotRethrownDebugLevel() throws Throwable { handler.setExceptionClassifier(new ExceptionClassifierSupport() { public Object classify(Throwable throwable) { return LogOrRethrowExceptionHandler.DEBUG; @@ -94,7 +94,7 @@ public class LogOrRethrowExceptionHandlerTests extends TestCase { assertNotNull(writer.toString()); } - public void testUnclassifiedException() throws Exception { + public void testUnclassifiedException() throws Throwable { handler.setExceptionClassifier(new ExceptionClassifierSupport() { public Object classify(Throwable throwable) { return "DEFAULT"; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/RethrowOnThresholdExceptionHandlerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/RethrowOnThresholdExceptionHandlerTests.java index 763e2430b..646d58074 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/RethrowOnThresholdExceptionHandlerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/RethrowOnThresholdExceptionHandlerTests.java @@ -31,7 +31,7 @@ public class RethrowOnThresholdExceptionHandlerTests extends TestCase { private RepeatContext parent = new RepeatContextSupport(null); private RepeatContext context = new RepeatContextSupport(parent); - public void testRuntimeException() throws Exception { + public void testRuntimeException() throws Throwable { try { handler.handleException(context, new RuntimeException("Foo")); fail("Expected RuntimeException"); @@ -40,7 +40,7 @@ public class RethrowOnThresholdExceptionHandlerTests extends TestCase { } } - public void testError() throws Exception { + public void testError() throws Throwable { try { handler.handleException(context, new Error("Foo")); fail("Expected Error"); @@ -49,7 +49,7 @@ public class RethrowOnThresholdExceptionHandlerTests extends TestCase { } } - public void testNotRethrownWithThreshold() throws Exception { + public void testNotRethrownWithThreshold() throws Throwable { handler.setExceptionClassifier(new ExceptionClassifierSupport() { public Object classify(Throwable throwable) { return "RuntimeException"; @@ -63,7 +63,7 @@ public class RethrowOnThresholdExceptionHandlerTests extends TestCase { assertEquals(1, counter.getCount()); } - public void testRethrowOnThreshold() throws Exception { + public void testRethrowOnThreshold() throws Throwable { handler.setExceptionClassifier(new ExceptionClassifierSupport() { public Object classify(Throwable throwable) { return "RuntimeException"; @@ -92,7 +92,7 @@ public class RethrowOnThresholdExceptionHandlerTests extends TestCase { } } - public void testNotUseParent() throws Exception { + public void testNotUseParent() throws Throwable { handler.setExceptionClassifier(new ExceptionClassifierSupport() { public Object classify(Throwable throwable) { return "RuntimeException"; @@ -111,7 +111,7 @@ public class RethrowOnThresholdExceptionHandlerTests extends TestCase { } } - public void testUseParent() throws Exception { + public void testUseParent() throws Throwable { handler.setExceptionClassifier(new ExceptionClassifierSupport() { public Object classify(Throwable throwable) { return "RuntimeException"; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/SimpleLimitExceptionHandlerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/SimpleLimitExceptionHandlerTests.java index 815f67151..8cae73f02 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/SimpleLimitExceptionHandlerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/SimpleLimitExceptionHandlerTests.java @@ -36,7 +36,7 @@ public class SimpleLimitExceptionHandlerTests extends TestCase { // object under test private SimpleLimitExceptionHandler handler = new SimpleLimitExceptionHandler(); - public void testInitializeWithNullContext() throws Exception { + public void testInitializeWithNullContext() throws Throwable { try { handler.handleException(null, new RuntimeException("foo")); fail("Expected IllegalArgumentException"); @@ -45,7 +45,7 @@ public class SimpleLimitExceptionHandlerTests extends TestCase { } } - public void testInitializeWithNullContextAndNullException() throws Exception { + public void testInitializeWithNullContextAndNullException() throws Throwable { try { handler.handleException(null, null); } catch (NullPointerException e) { @@ -58,7 +58,7 @@ public class SimpleLimitExceptionHandlerTests extends TestCase { * * @throws Exception */ - public void testNormalExceptionThrown() throws Exception { + public void testNormalExceptionThrown() throws Throwable { Throwable throwable = new RuntimeException("foo"); final int MORE_THAN_ZERO = 1; @@ -79,7 +79,7 @@ public class SimpleLimitExceptionHandlerTests extends TestCase { * * @throws Exception */ - public void testLimitedExceptionTypeNotThrown() throws Exception { + public void testLimitedExceptionTypeNotThrown() throws Throwable { final int MORE_THAN_ZERO = 1; handler.setLimit(MORE_THAN_ZERO); handler.setExceptionClasses(new Class[] {RuntimeException.class} ); @@ -96,7 +96,7 @@ public class SimpleLimitExceptionHandlerTests extends TestCase { * * @throws Exception */ - public void testLimitedExceptionNotThrownFromSiblings() throws Exception { + public void testLimitedExceptionNotThrownFromSiblings() throws Throwable { Throwable throwable = new RuntimeException("foo"); final int MORE_THAN_ZERO = 1; @@ -120,7 +120,7 @@ public class SimpleLimitExceptionHandlerTests extends TestCase { * * @throws Exception */ - public void testLimitedExceptionThrownFromSiblingsWhenUsingParent() throws Exception { + public void testLimitedExceptionThrownFromSiblingsWhenUsingParent() throws Throwable { Throwable throwable = new RuntimeException("foo"); final int MORE_THAN_ZERO = 1; @@ -145,7 +145,7 @@ public class SimpleLimitExceptionHandlerTests extends TestCase { * TransactionInvalidExceptions are swallowed until the exception limit is exceeded. After the limit is exceeded * exceptions are rethrown as BatchCriticalExceptions */ - public void testExceptionNotThrownBelowLimit() throws Exception { + public void testExceptionNotThrownBelowLimit() throws Throwable { final int EXCEPTION_LIMIT = 3; handler.setLimit(EXCEPTION_LIMIT); @@ -178,7 +178,7 @@ public class SimpleLimitExceptionHandlerTests extends TestCase { * TransactionInvalidExceptions are swallowed until the exception limit is exceeded. After the limit is exceeded * exceptions are rethrown as BatchCriticalExceptions */ - public void testExceptionThrownAboveLimit() throws Exception { + public void testExceptionThrownAboveLimit() throws Throwable { final int EXCEPTION_LIMIT = 3; handler.setLimit(EXCEPTION_LIMIT); diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/exception/handler/FootballExceptionHandler.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/exception/handler/FootballExceptionHandler.java index 2d4a4430c..9521a1427 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/exception/handler/FootballExceptionHandler.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/exception/handler/FootballExceptionHandler.java @@ -11,10 +11,10 @@ public class FootballExceptionHandler implements ExceptionHandler { .getLog(FootballExceptionHandler.class); public void handleException(RepeatContext context, Throwable throwable) - throws RuntimeException { + throws Throwable { if (!(throwable instanceof NumberFormatException)) { - throw new RuntimeException(throwable); + throw throwable; } else { logger.error("Number Format Exception!", throwable); }