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>
?
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>
<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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With