portal entry

select a category, or use search below
(searches all categories and all time range)

How to write onError method

| View in Portal
April 19, 2019 05:59:41 AM GMT
<p>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</p>
<p>The post <a rel="nofollow" href="https://coldfusion.adobe.com/2019/04/write-onerror-method/">How to write onError method</a> appeared first on <a rel="nofollow" href="https://coldfusion.adobe.com">ColdFusion</a>.</p>
Labels: Documentation, Public Beta Documentation, Question, ColdFusion, documentation, public beta documentation, question


<p>Start simple. In your application.cfc, add an onError function like the following:</p><p>function onError( any e ){<br />writeDump( var=e, label=”Primary error” );<br />abort;<br />}</p>
Comment by Steve Sommers
2003 | April 19, 2019 03:33:21 PM GMT
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 ?
2006 | April 21, 2019 05:03:40 PM GMT
<p>i have used the onRequest method,before using my starting page of application was running properly.but not now.</p><p> </p><p>and this is may on request function:</p><p><cffunction<br /> name="onRequestStart"<br /> access="public"<br /> returntype="boolean"<br /> output="false"<br /> hint="I execute when a request needs to be initialized."><br /><br /> <cfargument<br /> name="template"<br /> type="string"<br /> required="true"<br /> hint="I am the template that the user requested."/><br /> <cfsetting<br /> requesttimeout="10"<br /> showdebugoutput="false"/><br /> <cfreturn true /><br /> </cffunction></p><p><cffunction<br /> name="onRequest"<br /> access="public"<br /> returntype="void"<br /> output="true"<br /> hint="I execute the page template."><br /> <cfargument<br /> name="template"<br /> type="string"<br /> required="true"<br /> hint="I am the template that the user requested."/></p><p><cfinclude template="./index.cfm" /><br /> <cfreturn /><br /> </cffunction></p>
2007 | April 22, 2019 05:20:39 AM GMT
<p>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.</p><p>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:</p><p><a href="https://coldfusion.adobe.com/2016/03/new-coldfusion-training-videos-available/#comment-31549">https://coldfusion.adobe.com/2016/03/new-coldfusion-training-videos-available/#comment-31549</a></p><p>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. </p><p>I will now offer more thoughts given your other comments and your original question here.</p><p>You say things don’t work.. What doesn’t work?</p><p>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?</p><p>I realize your focus here is on error handling, and the resources I pointed to will help with that general question.</p><p>But are you currently seeing any error, on screen, in the cf application.log file?</p><p>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.</p>
Comment by Charlie Arehart
2008 | April 22, 2019 12:22:04 PM GMT
<p>Suggestion for a simple onError method:</p><p><cffunction name=”onError”><br /><cfargument name=”exception” required=true><br /><cfargument name = “eventName” required=true></p><p><p><cfoutput>OnError - event: #arguments.eventName#</cfoutput></p><br /> <cfdump var="#arguments.exception#" label="OnError: exception"> <br /></cffunction></p>
Comment by BKBK
2009 | April 22, 2019 12:51:55 PM GMT