cffinally

Used inside a cftry tag. Code in the cffinally block is processed after the main cftry code and, if an exception
occurs, the cfcatch code. The cffinally block code always executes, whether or not there is an exception.

  <cffinally>

 finally { }

Examples
Sample code using the cffinally tag

try {
	writeOutput('hello world<br/>');
	throw(message='threw on purpose!');
}catch(any e){
	writeOutput('Caught an exception<br/>');
}finally{
	writeOutput('Ran clean-up code regardless of error');
}

Expected Result: hello world Caught an exception Ran clean-up code regardless of error

<cftry>
	hello world<br/>
	<cfthrow message="threw on purpose!" />
	<cfcatch type="any">
		Caught an exception<br/>
	</cfcatch>
	<cffinally>
		Ran clean-up code regardless of error
	</cffinally>
</cftry>

Expected Result: hello world Caught an exception Ran clean-up code regardless of error

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub