CFCATCH Error in CFC

For some reason, a piece of code that works fine on a page *.cfmand works fine in *.cfc, now throws an error when an error is detected.

Error:

Element SQL is undefined in CFCATCH. 

The code block where this happens is as follows:

<cfcatch type="database">
    <cfset errorMessage = "
        <p>#cfcatch.message#</p>
        <p>Please send the following to a developer:</p>
        <p>#cfcatch.SQL#</p> <--- ERROR HERE
        <p>#cfcatch.queryError#</p>
        <p>#cfcatch.Where#</p>">
    some other stuff
</cfcatch>

Any thoughts?

UPDATE

Using the @BenKoshy suggestion, I changed the instruction <cfcatch>.

Remember K.I.S.? Keep It Simple Stupid

Using his method and then modifying it, I was getting more data than I used, so I went with a simple version and it works as advertised.

<cfif isDefined("cfcatch.message")>
  <cfset errorMessage = errorMessage & "<p>#cfcatch.message#</p>">
</cfif>
<cfif isDefined("cfcatch.SQL")>
    <cfset errorMessage = errorMessage & "<p>Please send the following to a developer:</p><p>#cfcatch.SQL#</p>">
</cfif>
<cfif isDefined("cfcatch.QueryError")>
    <cfset errorMessage = errorMessage & "<p>#cfcatch.queryError#</p>">
</cfif>
<cfif isDefined("cfcatch.Where")>
    <cfset errorMessage = errorMessage & "<p>#cfcatch.Where#</p>">
</cfif>

Nice and light and it works. KISS

+3
source share
1 answer

It simply means that the error data does not contain SQL statements. It should not be assumed that a variable will exist for all errors:

<cfif isDefined("cfcatch.sql")>
     <p>#cfcatch.SQL#</p>
 </cfif>

This is a simple fix. It is probably best to scroll through the structure as follows:

<cfparam name="errorMessage" default="">
<cfloop collection="#cfcatch#" item="this">
    <cfset errorMessage = errorMessage & "<p>#cfcatch[this]#</p>">
</cfloop>
+6
source

All Articles