2 Replies Latest reply on May 25, 2009 5:05 AM by salvo2

    OnError() function in web service: impossible?




      Context: A ColdFusion web service with application.cfc and OnError() function.


      I want the OnError function to log and email me when exceptions occur in web service but for some reason OnError() is never fired in such a case.

      It's weird because it works if a .cfm page is called instead of a .cfc!


      Is it a standard behaviour with CF webservice? Is there a workaround?



        • 1. Re: OnError() function in web service: impossible?
          Dan Bracuk Level 5

          I'm guessing your application.cfc does not play with your webservice cfc at all.


          The workaround is cftry/cfcatch for whatever function is being invoked as the webservice.

          1 person found this helpful
          • 2. Re: OnError() function in web service: impossible?
            salvo2 Level 1

            Hi Dan,


            Thank you for reading and suggesting. The fact is I would like to use onError() for what it is supposed to provide - and also to understand the mechanism.


            My onRequestStart() sets request variables to bar.cfc so application.cfc globally plays fine with the webservice cfcs. Well... except for error handling


            I found that if exception occurs in application.cfc it is actually caught by onError().

            But if exception occurs in webservice cfcs then it is not caught by onError() and a ugly SOAP error is sent to consumer instead.



            Here are my application.cfc and bar.cfc webservice components. They are pretty simple so I don't see why onError() is not fired:

            <cfcomponent displayname="Application" output="false">

                    this.Name                = "foo";
                    this.applicationTimeOut    = CreateTimeSpan(0,1,0,0);
                    this.sessionManagement    = false;
                    this.setClientCookies    = false;
                    this.clientManagement    = false;
                    this.scriptProtect        = "all";

                <cffunction name="onApplicationStart" access="public" output="false">

                    <cfset application.foo= "foo" />



                <cffunction name="onRequestStart" access="public" output="true">

                    <cfargument name="targetPage" type="string" required="true" />



                <cffunction name="onError" access="public" returnType="void" output="true">

                    <cfargument name="Exception" required="true" />
                    <cfargument name="EventName" type="string" required="true" />

                    <cfmail from="toto" to="admin@admin.com" subject="error">




            <cfcomponent displayname="bar">


                <cffunction name="test" access="remote" returntype="cpTest" output="false">

                 <!--- Throws an exception as b does not exist. This must be caught by onError() but it is not --->                   

                 <cfset a = b />





            Any clue?