Results 1 to 1 of 1

Thread: Try to work Checked Exceptions in doInTransactionWithoutResult

  1. #1
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,796

    Default Try to work Checked Exceptions in doInTransactionWithoutResult

    Hello

    I have this code

    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();		    
       	    }
            });
        }
    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.

    to rollback
    Code:
    	attr.getRollbackRules().add(new RollbackRuleAttribute(ArithmeticException.class));
    or dont rollback
    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

    [javac] .......java:128: unreported exception java.io.IOException;
    must be caught or declared to be thrown
    [javac] throw new IOException();

    [javac] ^
    [javac] 1 error
    How I can handle this?

    or is mandatory only to work with unchecked exceptions?
    I dont want handle any exception inside doInTransactionWithoutResult method

    Thanks in advanced
    Last edited by dr_pompeii; Aug 21st, 2009 at 03:30 PM.
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •