Hello
I have this code
If I dont comment throw new ArithmeticException(); (and yes IOException of course), I dont recieve any compile errors (because is a unchecked exception), the rollback rule works fine.Code:public void purchase(final String isbn, final String username)throws Exception { RuleBasedTransactionAttribute attr = new RuleBasedTransactionAttribute(); attr.getRollbackRules().add(new RollbackRuleAttribute(IOException.class)); attr.getRollbackRules().add(new NoRollbackRuleAttribute(ArithmeticException.class)); TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager,attr); transactionTemplate.execute(new TransactionCallbackWithoutResult() { protected void doInTransactionWithoutResult( TransactionStatus status) { ....some logic with persistence throw new ArithmeticException(); //throw new IOException(); } }); }
to rollback
or dont rollbackCode:attr.getRollbackRules().add(new RollbackRuleAttribute(ArithmeticException.class));
Code:attr.getRollbackRules().add(new NoRollbackRuleAttribute(ArithmeticException.class));
but If I dont comment throw new IOException(); like
Code:....some logic with persistence //throw new ArithmeticException(); throw new IOException();
I recieve instead
How I can handle this?[javac] .......java:128: unreported exception java.io.IOException;
must be caught or declared to be thrown
[javac] throw new IOException();
[javac] ^
[javac] 1 error
or is mandatory only to work with unchecked exceptions?
I dont want handle any exception inside doInTransactionWithoutResult method
Thanks in advanced


Reply With Quote