Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I use CFTRANSACTION

Error Trapping

How can I use CFTRANSACTION

by  webmigit  Posted    (Edited  )
Speaking about: http://livedocs.macromedia.com/coldfusion/6/CFML_Reference/Tags-pt315.htm

This is not a very good example of how to employ CFTRANSACTION, it does not show how to use the various actions.. Its pretty much a shot in the dark unless you get the livedocs for CF5 (which is more detailed) but following the code there is invalid because cftry requires the last tag executed within itself be cfcatch.. so the method of catching and setting a variable in that method doesn't work.. This is how you need to do it..

Code:
<Cfset gotrue=1>
<cftransaction>
  <cftry>...queries here...
    <cfcatch>...catch the error...
      <cfset gotrue=0>
      <cftransaction action="rollback">
      <cfrethrow> <!---This line throws the error back to your error handler if you have one.. If you don't, you can remove this...--->
    </cfcatch>
  </cftry>
  <cfif gotrue eq 1>
    ...do something...
    <cftransaction action="commit">
  </cfif>
</cftransaction>

Livedocs really needs to improve this page, very badly...

You may also notice that I posted this same comment on the livedocs page. I'm severely disappointed in Macromedia on the documentation of that page.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top