On Tuesday, Oct 15, 2002, at 01:32 US/Pacific, Kola Oyedeji wrote:
> Sean, have I missed something, are you saying try and catch add a
> significant performance overhead?

try/catch is not an efficient way to solve the problem posed. try/catch 
is designed for unexpected error conditions and should not really be 
used for 'expected' results.

This is both a stylistic issue and a performance issue.

Example:
        You iterate over a list. You know you're going to hit the end of the 
list (because all lists have an end). Do you throw an exception when 
you hit the end of the list?
        a) If you are looking for something that should always be present - 
and not finding it indicates a logic error in your program - then an 
exception is appropriate.
        b) If you are looking for something that might not be present then an 
exception is NOT appropriate (because you 'expect' to not find it 
sometimes).

In general, throw/catch will be 'slower' than (most) other ways of 
'returning' error information. Note that try should place little or no 
overhead on code that does not actually throw any exceptions.

If you think about how throw/catch operate, you should be able to see 
why this is so. When you throw an exception, CF has to walk up the 
stack of active invocations / try blocks to locate a catch that matches 
the type of the throw. Most times, it won't have to walk very far - CF 
programmers typically catch any exception rather than having a complex 
layered exception model - but it's still a slower process than simple 
cfreturn or just setting a variable (as in my earlier reply).

"I can smell your brains!"
-- Mittens the Kitten : http://www.matazone.co.uk/theotherside.html

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Reply via email to