onError function in Application.cfc


while use new functions come mx in application.cfc still don't have feel of them. below use onerror function based on other peoples code , own experience. tweaking used generic function.

<cffunction name="onerror" returntype="void" access="public" hint="fires when error generated not caught cftry / cfcatch">

<!--- gives info on error --->
<cfargument name="exception" type="any" required="true">
<cfset var except = arguments.exception>


<!--- if sessionexpiration becomes true redirect local home page--->
<cfset var sessionexpiration = false>
<cfset var redirecturl= "/index.cfm">


<!--- exit if exception caused cfabort tag or event handler --->
<cfif (arguments.exception "coldfusion.runtime.abortexception")
or (arguments.exception "coldfusion.runtime.eventhandlerexception: event handler exception.") >
<cfreturn/> </cfif>


<!--- sort out session variables after person has logged out? --->
<cfif structkeyexists(except,"rootcause") , structkeyexists(except["rootcause"],"detail")>
<cfif except["rootcause"]["detail"] contains "session invalid">
<cfset sessionexpiration = true>
</cfif>
</cfif>

<!--- using j_username paramters in login can cause
confusion session status after logout - tidy
expiring session , redirecting --->
<cfif sessionexpiration>

<cfcookie name="jsessionid" value="" expires="now">
<cfheader statuscode="302" statustext="moved temporarily">
<cfheader name="location" value="#redirecturl#">


<cfelse> <!--- real error show message , contact adminsitrator --->

<!--- supposed hand on control of error cferror tags --->
<cfmail to="#request.siteadmin#" from="someemail@someserver.com"
subject="error diagnostics" server="#request.mailserver#">
there error on: #request.thisaddress#
...................................................
brief detail is: #except#
</cfmail>

<!--- hand on cferror tags --->
<cfthrow object="#arguments.exception#">

</cfif> <!--- sessionexpiration --->

</cffunction>

<cferror type="exception" template="error_messages/general_error.cfm">
<cferror type="validation" template="error_messages/validationerror.cfm" >
<cferror type="request" template="error_messages/general_error.cfm">

apologies, submitted before got ask questions
1) why cfabort , handler exceptions appearing when didn't using application.cfm , cferror tag?
2) above code sort out status of session variables after person logs out? if not can dealt in function?
3) @ moment don't use cfthrow , cferror tags because keep getting template not found error despite same code having worked fine in application.cfm
i put i'm sure other people must running similar issues. comments welcome!


More discussions in Advanced Techniques


adobe

Comments

Popular posts from this blog

Qualcuno mi sa dire perchè non va questo protocollo seriale ?

Prezzemolo!

play video