Results 1 to 6 of 6

Thread: Getting failure exceptions from the job repository

  1. #1
    Join Date
    Aug 2004
    Location
    France - Saint Nazaire
    Posts
    79

    Question Getting failure exceptions from the job repository

    Hello,

    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!
    Thierry

  2. #2
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    The failure exceptions are transient (not persisted in the repository), so they are only accessible when the StepExecution is still active.

  3. #3
    Join Date
    Dec 2010
    Posts
    27

    Default

    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.

  4. #4
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    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.

  5. #5
    Join Date
    Dec 2010
    Posts
    27

    Default

    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.

  6. #6
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •