April 19, 2019
How to write onError method
Comments
(5)
April 19, 2019
How to write onError method
Newbie 5 posts
Followers: 2 people
(5)

I want to display the custom errror…I am not getting how to start the code…Or how to start writing onError method,can u help me with the flow and if possible send some sample code for hadling the custom error

5 Comments
2019-04-22 12:51:55
2019-04-22 12:51:55

Suggestion for a simple onError method:

<cffunction name=”onError”>
<cfargument name=”exception” required=true>
<cfargument name = “eventName” required=true>

<p><cfoutput>OnError – event: #arguments.eventName#</cfoutput></p>
<cfdump var=”#arguments.exception#” label=”OnError: exception”>
</cffunction>

Like
2019-04-22 05:20:39
2019-04-22 05:20:39

i have used the onRequest method,before using my starting page of application was running properly.but not now.

 

and this is may on request function:

<cffunction
name=”onRequestStart”
access=”public”
returntype=”boolean”
output=”false”
hint=”I execute when a request needs to be initialized.”>

<cfargument
name=”template”
type=”string”
required=”true”
hint=”I am the template that the user requested.”/>
<cfsetting
requesttimeout=”10″
showdebugoutput=”false”/>
<cfreturn true />
</cffunction>

<cffunction
name=”onRequest”
access=”public”
returntype=”void”
output=”true”
hint=”I execute the page template.”>
<cfargument
name=”template”
type=”string”
required=”true”
hint=”I am the template that the user requested.”/>

<cfinclude template=”./index.cfm” />
<cfreturn />
</cffunction>

Like
2019-04-19 15:33:21
2019-04-19 15:33:21

Start simple. In your application.cfc, add an onError function like the following:

function onError( any e ){
writeDump( var=e, label=”Primary error” );
abort;
}

Like
(2)
>
Steve Sommers
's comment
2019-04-21 17:03:40
2019-04-21 17:03:40
>
Steve Sommers
's comment

Thank you Steve Sommers

How to call this onError method and where we need to call? or it will be called when the application got started ?

Like
>
sangeetab51931146
's comment
2019-04-22 12:22:04
2019-04-22 12:22:04
>
sangeetab51931146
's comment

Sanjeet  you ask how to use onerror. I pointed out in another comment in another thread that you could find several working examples showing EXACTLY how, where, and why to add error handling–specifically the onerror method of application.cfc.

Please tell us if you have read all 3 specific references I made. You should not need to ask your question of Steve if you had:

https://coldfusion.adobe.com/2016/03/new-coldfusion-training-videos-available/#comment-31549

I’m not saying this to scold  but to get us all on the same page–especially since you have asked about this in two places. Let’s keep going here  for now. 

I will now offer more thoughts given your other comments and your original question here.

You say things don’t work.. What doesn’t work?

Is it that your index.cfm, listed in the onrequest method, does not run? And why do you have that? What if you removed it?

I realize your focus here is on error handling, and the resources I pointed to will help with that general question.

But are you currently seeing any error, on screen, in the cf application.log file?

If there’s no error in the application.log file, then it would seem you have some error handler in place, perhaps the site wide error handler. Maybe the error is being tracked somewhere in that. Again, see the resources on cf error handling that I pointed out, for more.

Like
Add Comment