User Guide

Table Of Contents
294 Chapter 13: Designing and Optimizing a ColdFusion Application
<cflock timeout="5" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
<cfset Application.sessions = Application.sessions + 1>
</cflock>
<cflog file="#This.Name#" type="Information" text="Session:
#Session.sessionid# started">
</cffunction>
<cffunction name="onSessionEnd">
<cfargument name = "SessionScope" required=true/>
<cflog file="#This.Name#" type="Information" text="Session:
#arguments.SessionScope.sessionid# ended">
</cffunction>
<cffunction name="onError">
<cfargument name="Exception" required=true/>
<cfargument type="String" name = "EventName" required=true/>
<!--- Log all errors. --->
<cflog file="#This.Name#" type="error" text="Event Name: #Eventname#">
<cflog file="#This.Name#" type="error" text="Message: #exception.message#">
<!--- Some exceptions, including server-side validation errors, do not
generate a rootcause structure. --->
<cfif isdefined("exception.rootcause")>
<cflog file="#This.Name#" type="error"
text="Root Cause Message: #exception.rootcause.message#">
</cfif>
<!--- Display an error message if there is a page context. --->
<cfif NOT (Arguments.EventName IS onSessionEnd) OR
(Arguments.EventName IS onApplicationEnd)>
<cfoutput>
<h2>An unexpected error occurred.</h2>
<p>Please provide the following information to technical support:</p>
<p>Error Event: #EventName#</p>
<p>Error details:<br>
<cfdump var=#exception#></p>
</cfoutput>
</cfif>
</cffunction>
</cfcomponent>
Migrating from Application.cfm to Application.cfc
To migrate an existing application that uses Application.cfm to one that uses Application.cfc, do
the following:
Replace the cfapplication tag with CFC initialization code that sets the Application.cfc This
scope variables that correspond to the tag attributes.
Put in the onApplicationStart method any code that initializes Application scope variables,
and any other application-specific code that executes only when the application starts. Often,
such code in Application.cfm is inside a block that tests for the existence of an Application
scope switch variable. Remove the variable test and the Application scope lock that surrounds
the code that sets the Application scope variables.