Skip to main content
Inspiring
July 29, 2009
Question

cfcatch cftry for cfquery

  • July 29, 2009
  • 1 reply
  • 1006 views

Hi everyone,

If a cftry only contain a cfquery is it true that the only cfcatch type possible to create an exception will be type "database" ?

Any body knows ?

Thanks in advance,

Chantal

    This topic has been closed for replies.

    1 reply

    BKBK
    Community Expert
    Community Expert
    July 31, 2009
    If a cftry only contain a cfquery is it true that the only cfcatch type possible to create an exception will be type "database" ?

    No, that's false. A cfcatch of any type is possible. It all depends what kind of exception you expect to catch.

    A cfcatch of type database will only catch database exceptions. If, for example, the query uses a  dynamic variable that may divide by zero, then it might be appropriate to catch an exception of type 'expression' or 'application'.

    <!--- Type 'expression' more appropriate here than type 'database' --->
    <cfset dynamicVar = 0>
    <cftry>
    <cfquery name="q" datasource="dsn">
        select *
        from myTable
        where id = #1/dynamicVar#
    </cfquery>
    <cfcatch type="expression" >
        <cfdump var="#cfcatch#">
    </cfcatch>
    </cftry>

    If you wish to catch an exception of type database, exception or application in a blanket way, then you should use type 'any'.