I'm not sure, would need some testing, but I may have thought of a valid
reason for this code, maybe.  The cfcatch does not have a type parameter, it
is going to catch all errors not just the throw, isn't it?  In that case it
is serving multiple use and could be a good thing.  But the trouble with
this, if it was intended, is that they will all get a whyBadBid of Invalid
item number, no matter the error.



--------------
Ian Skinner
Web Programmer
BloodSource
Sacramento, CA


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 25, 2003 1:26 AM
To: CF-Community
Subject: Best practice? CFTHROW


I've got some code here where the author set up a CFTRY block, did a query
in it
and then tested the query values. If it failed, he ran a CFTROW and handled
the
failure in a CFCATCH (the code is below).
Now can someone, anyone tell me why he didn't just put the two CFSETs from
the
CFCATCH into the CFELSE? Is there some best practice to use CFTHROW in this
manner? It seems exceptionally wasteful especially as this will be recorded
as
an error in the logs.  He doesn't seem focused on catching an error from the
query, just from the query results. (the code is FULL of instances of this
and
is a reason I will never recomend this product to anyone)

 <cftry>
  <cfquery username="#db_username#" password="#db_password#" name="getItem"
datasource="#Attributes.datasource#">
   SELECT COUNT(itemnum) AS found
   FROM items
   WHERE itemnum = #Attributes.itemnum#
  </cfquery>

  <cfif getItem.found>
   <cfset chkItemnum = "TRUE">
  <cfelse>
   <cfthrow>
  </cfif>

  <cfcatch>
   <cfset chkItemnum = "FALSE">
   <cfset whyBadBid = ListAppend(whyBadBid, "Invalid item number.", ",")>
  </cfcatch>
 </cftry>

Michael Dinowitz
Master of the House of Fusion
http://www.houseoffusion.com


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=5
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=5
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

                                Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.5
                                

Reply via email to