throw failure;
} catch (Error e) {
// Log this in case the finally clause below masks it with another exception.
log.log(Level.SEVERE, "Error in doWork()", e);
addPermanentFailureMessages(messagesToSend,
new PermanentFailure("Error in doWork()", e));
throw e;
} catch (RuntimeException e) {
// Log this in case the finally clause below masks it with another exception.
log.log(Level.SEVERE, "RuntimeException in doWork()", e);
addPermanentFailureMessages(messagesToSend,
new PermanentFailure("RuntimeException in doWork()", e));
throw e;
} finally {
// Note that it is possible that messagesToSend is empty: If the batch succeeded and
// all results were rejections.
List<QueueItem> removed = removeWaitingItems(messagesToSend.size());