- February 8, 2017
- Posted by: iSummation Team
- Category: Uncategorized
ColdFusion 9 introduced cffinally tag. Cffinally or finally blocks are used within cftry or completion of try block. It is generally used for cleanup i.e. close database connections, close some objects or excecute code whether it is exception or not.
Data output tag and error handling.
Generally we use try and catch block to catch exception like application error, database error, custom error etc. But sometimes we need to run some code whether it is exception or not so generally we need to write both of it in catch block as well as after try block but now in ColdFusion 9 has introduced cffinally and many more useful tags. cffinally tag always use in try block. You can nest cftry/cfcatch/cffinally blocks. Cffinally tag executes code whether it is exception or not. You can also use finally in cfscript tag. These tags are meant for error handling. I hope it may be useful for you.
<cfset a = 10>
<cfset b = 0>
<cfset a = a / b>
<cfoutput><b>Ans : </b>#a#</cfoutput>
<br /><b>Finally Block :</b>
a = 10;
b = 0;
a = a / b;
writeOutput(‘<b>Ans : #a#</b>’);
writeOutput(‘<br /><b>Finally Block : </b>’);
Division by zero.
Finally Block : 10