When using an ItemWriteListener (or the like) from Spring Batch, what is the proper way to handle checked exceptions that were passed to listener delegates?
For instance:
public class MyClass implements ItemWriteListener<MyDTO> { // fields and constructor omitted @Override public void beforeWrite(List<MyDTO> items) { try { repository.loadAll(); // <-- Throws some checked exception } catch (Exception e) { // What to do here? } } // other methods omitted }
How should I handle this exception? Here are some ideas:
- Repeat in
RuntimeException - Record the exception and let the step fail along the line where it depends on the action of this listener
- Set some indicator in
MyDTO elements to indicate failure
Of course, I cannot throw a checked exception because it is not declared in the ItemWriteListener interface.
source share