Files
spring-batch/build/reference-epub-work/ch08s03.xhtml
Michael Minella 75ab909314 update
2017-03-23 10:18:33 -05:00

24 lines
2.4 KiB
HTML

<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:pls="http://www.w3.org/2005/01/pronunciation-lexicon" xmlns:ssml="http://www.w3.org/2001/10/synthesis" xmlns:svg="http://www.w3.org/2000/svg"><head><title>Exception Handling</title><link rel="stylesheet" type="text/css" href="docbook-epub.css"/><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"/><link rel="prev" href="ch08s02.xhtml" title="Completion Policies"/><link rel="next" href="ch08s04.xhtml" title="Listeners"/></head><body><header/><section class="section" title="Exception Handling" epub:type="subchapter" id="repeatExceptionHandling"><div class="titlepage"><div><div><h2 class="title" style="clear: both">Exception Handling</h2></div></div></div><p>If there is an exception thrown inside a
<code class="classname">RepeatCallback</code>, the
<code class="classname">RepeatTemplate</code> consults an
<code class="classname">ExceptionHandler</code> which can decide whether or not to
re-throw the exception.</p><pre class="programlisting">public interface ExceptionHandler {
void handleException(RepeatContext context, Throwable throwable)
throws RuntimeException;
}</pre><p>A common use case is to count the number of exceptions of a
given type, and fail when a limit is reached. For this purpose Spring
Batch provides the <code class="classname">SimpleLimitExceptionHandler</code> and
slightly more flexible
<code class="classname">RethrowOnThresholdExceptionHandler</code>. The
<code class="classname">SimpleLimitExceptionHandler</code> has a limit property
and an exception type that should be compared with the current exception -
all subclasses of the provided type are also counted. Exceptions of the
given type are ignored until the limit is reached, and then rethrown.
Those of other types are always rethrown.</p><p>An important optional property of the
<code class="classname">SimpleLimitExceptionHandler</code> is the boolean flag
<code class="code">useParent</code>. It is false by default, so the limit is only
accounted for in the current <code class="classname">RepeatContext</code>. When
set to true, the limit is kept across sibling contexts in a nested
iteration (e.g. a set of chunks inside a step).</p></section><footer/></body></html>