transaction { 
   try { 
      // code to run 
      transaction action="commit"; 
   } 
   catch(any e) { 
      transaction action="rollback"; 
   } 
}   

try-catch is optional in transaction but is used most of the time.