Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ColdFusion CFTRY and CFCATCH confusion

Tags:

coldfusion

I am trying to use a <cftry> and <cfcatch> block of code. However I am confused about something, I put a <cftry> block around my query and the result of that query is not empty, but the condition always goes into the <cfcatch> block.

Example :

<cftry>
  <cfquery name="qcar" datasource="xxxx">
     select * from allcar
   </cfquery>
<cfcatch>
   <script>
      alert("ERROR");
   </script>
</cfcacth>
</cftry>

What is wrong with this code that it always goes to the <cfcatch>?

like image 260
Windy Sinaga Avatar asked Jul 31 '15 03:07

Windy Sinaga


2 Answers

You have a typo in your code, the code in your answer should not even pass the syntax check. Please correct both - the code in your question and the one on your server, and check whether this solves your problem. If this is not the case, please apply a <cfdump var="#cfcatch#" />, like @beloitdavisja told you and show as further error messages. The typo is in line 9, </cfcacth> should be </cfcatch>.

<cftry>
    <cfquery name="qcar" datasource="xxxx">
        select * from allcar
    </cfquery>

    <cfcatch type="any">
        <!--- Your debug output <script>alert("ERROR");</script>--->
        <!--- Debugging - The ColdFusion Way --->
        <cfdump var="#cfcatch#" />
    </cfcatch>
</cftry>
like image 76
Stefan Braun Avatar answered Oct 23 '22 03:10

Stefan Braun


<cftry>

    <cfquery name="qEmployee" datasource="cfdocexamples">
          SELECT * FROM Employeess
    </cfquery>


 <cfcatch type="any">
       <cfoutput>
          Error occured....<br /><br />
        Message: <b>#cfcatch.Message#</b><br /> 
        Detail: <b>#cfcatch.Detail#</b><br />
        Type: <b>#cfcatch.Type#</b><br />

      </cfoutput>
  </cfcatch>
</cftry>

Note: #cfcatch# give full details in json format

#cfcatch.Message# give you only error message in string format

like image 5
hoogw Avatar answered Oct 23 '22 03:10

hoogw