/** * Override this method to override how the Template executes the callback. * You probably shouldn't need to override this; but who am I to judge? * * @param callback {@link TransactionMonitorCallback} to execute * @param monitor {@link TransactionMonitor} to use * @return anything the callback returns */ protected Object executeCallback(TransactionMonitorCallback callback, TransactionMonitor monitor) { try { // This looks wrong but it's intentional. We want to allow the callback to // mark the monitor as failed in its code, even if it didn't throw an exception. // Therefore, we're turning the fail-by-default TransactionMonitor into // a succeeded-by-default object. monitor.succeeded(); return callback.doInMonitor(monitor); } catch (RuntimeException e) { monitor.failedDueTo(e); throw e; } catch (Error e) { monitor.failedDueTo(e); throw e; } finally { monitor.done(); } }
monitor.failedDueTo(t); throw t;