I am looking for a generic code template for the correct processing of a transaction regarding a possible exception. I assume that for this there is a common code template, regardless of the specific type of transaction with which we are dealing.
I have a method that executes something in a transaction and wants to reconstruct an exception that can occur when inside a block of transactional code. Here is an example of such a method:
protected void doIt() {
Tran tran = session.beginTran();
try {
tran.commit();
} catch (Exception ex) {
tran.rollback();
throw ex;
}
}
- doIt. throws Exception, , doIt , throws Exception doIt. - Java .
: - ( ) , .
, - throw new RuntimeException(ex), , .