Oct 20th, 2010, 11:47 AM
Getting failure exceptions from the job repository
I have a small question regarding the way to get failure exceptions from the job repository.
I have a job execution which failed when parsing a line within the input file. I can get the error in the exit description of the corresponding step execution but I can't find the exception in the list returned by the getFailureExceptions method. I wonder if it's a normal behavior. If true, what kinds of exceptions are put in this list...
Thanks very much for your help!
Oct 30th, 2010, 10:49 AM
The failure exceptions are transient (not persisted in the repository), so they are only accessible when the StepExecution is still active.
Feb 9th, 2011, 05:08 AM
Then, what is the recommended way to catch any Java exception (both checked and runtime ones, either thrown by Spring Batch framework or by business logic) that occurred during job execution?
Instead of implementing StepExecutionListener to get exceptions by stepExecution.getFailureExceptions() for each step, is there a way to catch all exceptions at a facade level, with a single piece of code?
I think JobExecutionListener.afterJob() is good place to catch any exception during job execution, because this function executes even the job fails. Can I catch any exeception in afterJob()?
Last edited by hyjshanghai; Feb 9th, 2011 at 07:29 PM.
Feb 9th, 2011, 08:46 AM
No exceptions should be thrown from a step or job if it completes or fails (normal execution), so there's nothing to catch, but you can certainly inspect the failure exceptions in all the step executions in a job listener.
Feb 9th, 2011, 07:07 PM
This is exactly what I am doing now in jobExecutionListener.afterJob():
1. Collect all failure exceptions from jobExecution.getFailureExceptions().
2. For each stepExecution in jobExecution.getStepExecutions():
Collect all failure exceptions from stepExecution.getFailureExceptions().
3. Report all these collected exceptions for diagnosis purposes.
Will the above guarantee to collect exceptions caused not only by business logic, but also by the Spring Batch framework's logic?
Last edited by hyjshanghai; Feb 9th, 2011 at 07:12 PM.
Feb 10th, 2011, 10:16 AM
There's no such thing as a guarantee. We make every effort to collect all the failure exceptions. If you find one that is missed let us know.