Well, it depends on what you want the flow to be, but here's the start.

<CFTRY>
  [Query or other potentially problematic code]
  <CFCATCH type="Database">
    [Exception processing code]
  </CFCATCH>
</CFTRY>
[After running CFCATCH block, code resumes processing here.]

If you just want a friendly message, then you can have the CFCATCH block
(whose type attribute in the above example specifies that it only handles
CFQUERY-related errors) CFLOCATION to an error page.  If you think you might
be able to fix the problem, then you can possibly try the query again (by
re-submitting this page to itself if it's a form action page, for example,
only with corrected parameters passed).

The thing is if you know how to fix it when it happens, perhaps a
pre-emptive strike is better?  For example, if a value should be numeric,
you can test for that before submitting it to the query.  Still use
CFQUERYPARAM (for performance reasons, if nothing else), but that way you
avoid having to see the error first.

More specifics on CFTRY/CFCATCH: If you don't yet know how the above works,
here's the flow.  When the "potentially problematic code" in the CFTRY block
throws an error at any point, processing immediately jumps to the CFCATCH
block(s).  If the error matches the specified type, it runs the code in the
CFCATCH block.  If the error does not match, it goes to another CFCATCH
block, if you have one for multiple types.  If it never finds a CFCATCH
block with a matching error type, I think that it just throws an error the
old-fashioned way.  Here's the really important thing to remember, though:
assuming that a CFCATCH block with matching error type is found, the code in
the CFCATCH block is run, and then processing jumps to the line IMMEDIATELY
AFTER THE CLOSING </CFTRY> TAG.  It does NOT go back to where the error
happened.  This commonly gets confused.

Hope this helps,
Matthieu


-----Original Message-----
From: Ian Skinner [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 08, 2003 11:59 AM
To: CF-Talk
Subject: CFQueryParam and Error Handling


I'm trying to step up my coding standards and start using <cfqueryparam>'s
in my Database calls. What I would like to know is how I should catch
error's thrown by improper data passed to the queryparam?  I've scanned
through the <cftry><cfcatch> and the <cferror> documentation, but I'm not
readily understanding how to use either one to catch error's in data passed
to a <cfqueryparam> and provide logic to handle it.

Thanks
Ian Skinner
Web Developer
Blood Source

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: 
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
This list and all House of Fusion resources hosted by CFHosting.com. The place for 
dependable ColdFusion Hosting.

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

Reply via email to