Well it depends.

I am a big fan of using try/catch/throw/finally statements, but I use
them together.

In this case, the developer may have wanted to ensure that the code in
the Catch block was run on a DB error or an empty record set. To me this
is a type of error. If I get to a page where a record is expected but it
doesn't exist, that is an error and I treat it as such.

I use throws for User Authentication systems, if the username/password
is bad, I throw an error, which is usually caught somewhere, but it can
be dealt with by the application.

Here throw was used to make sure the same code is run in the event of an
error or an empty record set. It was used to consolidate the code.

Now if the programmer knew that is what he was doing is an entirely
different question.

> -----Original Message-----
> From: Michael Dinowitz [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, March 25, 2003 4: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
Get the mailserver that powers this list at http://www.coolfusion.com

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

Reply via email to