ColdFusion - How to catch exception and handle error

cftry and cfcatch - catch exception and handle error

cftry.cfm


<!DOCTYPE html">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>cftry and cfcatch tag example: how to catch exception and handle error</title>
</head>

<body>
<h2 style="color:DodgerBlue">ColdFusion cftry and cfcatch example</h2>

<cftry>
 <!---Here i input wrong table name--->
 <cfquery name="qEmployee" datasource="cfdocexamples">
     SELECT * FROM Employeess
    </cfquery>
    <cfdump var="#qEmployee#">

    <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>

</body>
</html>





More ColdFusion examples