Announcement Announcement Module
No announcement yet.
Catching Exception Thrown form Job Listener? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Catching Exception Thrown form Job Listener?

    The JobListener is able to catch any exception thrown in a job, as step/jobExecution.failureException.

    For integration purposes, I want the client who loads and starts the Spring Batch job to access these exception objects.

    So, if I throw an exception in a JobListener, is it guaranteed that the client program will always be able to catch the exception?

    Here, "the client program" refers to the main program who loads the application context of the Spring Batch job and starts the job. I want the Java Exception object thrown inside the Spring Batch job accessible by the client program, rather than "swallowed" by JobListener.afterJob().

  • #2
    Job and Step are not supposed to throw exceptions even if they fail. Your program should be able to retrieve the exceptions from a local execution via the *Execution objects. Then it can rethrow. I guess this amounts to writing a wrapper for the JobLauncher.


    • #3
      Failure executions referenced by Job / StepExecution objects are available only before the Spring Batch job ends.

      In our case, the Spring Batch job is just one stage of our whole main program. It is our main program that is designed to provide universal exception handling, such as logging any exception in a database.

      However, currently, we cannot get exceptions happened during the Spring Batch job in the main program, AFTER the spring batch job ends.

      We have to copy the exception handling logic into JobExecutionListener.afterJob() for the Spring Batch job, which is kind of code duplication.