RESOLVED - issue BATCH-457: Error handling broken in SimpleJob

Look out for Error types explicitly and re-throw them without wrapping
This commit is contained in:
dsyer
2008-03-14 08:53:27 +00:00
parent 1a316c1aa9
commit 4fd2968e5e
8 changed files with 302 additions and 151 deletions

View File

@@ -35,21 +35,22 @@ public class DefaultExceptionHandler implements ExceptionHandler {
* Throwable)
*/
public void handleException(RepeatContext context, Throwable throwable) throws RuntimeException {
rethrow(throwable);
}
/**
* Convenience method to rethrow the Throwable instance. Wraps it in a {@link RepeatException} if it is not a
* {@link Exception}.
* {@link RuntimeException} or {@link Error}.
*
* @param throwable a Throwable.
* @throws RuntimeException if the throwable is a {@link RuntimeException} just rethrow, otherwise wrap in a
* {@link RepeatException}
* @throws RuntimeException if the throwable is a {@link RuntimeException}
* @throws Error if the throwable is an {@link Error}
* @throws RepeatException otherwise
*/
public static void rethrow(Throwable throwable) throws RuntimeException {
if (throwable instanceof RuntimeException) {
if (throwable instanceof Error) {
throw (Error) throwable;
} else if (throwable instanceof RuntimeException) {
throw (RuntimeException) throwable;
} else {
throw new RepeatException("Exception in batch process", throwable);

View File

@@ -27,7 +27,6 @@ import org.springframework.batch.repeat.CompletionPolicy;
import org.springframework.batch.repeat.ExitStatus;
import org.springframework.batch.repeat.RepeatCallback;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.RepeatException;
import org.springframework.batch.repeat.RepeatListener;
import org.springframework.batch.repeat.RepeatOperations;
import org.springframework.batch.repeat.exception.DefaultExceptionHandler;
@@ -290,12 +289,8 @@ public class RepeatTemplate implements RepeatOperations {
* @param next
* @return
*/
private static Exception rethrow(Throwable next) throws RuntimeException {
if (next instanceof RuntimeException) {
throw (RuntimeException) next;
}
;
throw new RepeatException("Rethrowing exception that is no RuntimeException.", next);
private static void rethrow(Throwable next) throws RuntimeException {
DefaultExceptionHandler.rethrow(next);
}
/**