Good Q, either way is "correct" I suppose...like you noted it's developer
preference.

Obviously with the CFIF method you are not catching a CF error per se - you
are preventing it from happening full stop and catching it with defensive
coding.  In some cases such as a URL I would simply refresh the current page
back to the pre-manipulated/non numeric ID URL.

I suppose in the case of passing an ID say from a form I would try and catch
it via JS first, then via CF but the whole CFIF block would be in a
cftry/block as well to catch for any unforeseen errors no necessarily
related to the ID.







-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: 15 February 2006 15:38
To: CF-Talk
Subject: Try/Catch vs. direct error handling

This is a question of best practices and why. When I know there's a chance
of a specific error, I tend to code specifically to handle it. Others code
generally using try/catch. Which is seen as best in other languages and why?
I doubt there's any real performance issue between them, so it's a question
of industry standard and style.

For example, if I know an ID is needed on a page and it has to be a numeric
I'd do:
<CFIF Not IsDefined('ID')>
        An ID is needed
<CFELSEIF Not IsNumeric(ID)>
        The passed ID needs to be numeric
</CFIF>

Others do:
<CFTRY>
        <cfparam name="ID" type="numeric">
        <CFCATCH>
                You must pass a numeric ID
        </CFCATCH>
</CFTRY>




~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:232330
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to