myObj = createObject("component", "myCFC"); // catch errors try { bResult = myObj.getlist(); } catch (databaseError cfcatch) { writeOutput(cfcatch.message); writeOutput(cfcatch.detail); } SELECT * FROM T_USER ORDER BY #_orderby# #_order# [allowsmilie] => 1 [showsignature] => 0 [ipaddress] => [iconid] => 0 [visible] => 1 [attach] => 0 [infraction] => 0 [reportthreadid] => 0 [isusenetpost] => 1 [msgid] => [ref] => [htmlstate] => on_nl2br [postusername] => Stressed_Simon [ip] => webforumsuser@m [isdeleted] => 0 [usergroupid] => [membergroupids] => [displaygroupid] => [password] => [passworddate] => [email] => [styleid] => [parentemail] => [homepage] => [icq] => [aim] => [yahoo] => [msn] => [skype] => [showvbcode] => [showbirthday] => [usertitle] => [customtitle] => [joindate] => [daysprune] => [lastvisit] => [lastactivity] => [lastpost] => [lastpostid] => [posts] => [reputation] => [reputationlevelid] => [timezoneoffset] => [pmpopup] => [avatarid] => [avatarrevision] => [profilepicrevision] => [sigpicrevision] => [options] => [akvbghsfs_optionsfield] => [birthday] => [birthday_search] => [maxposts] => [startofweek] => [referrerid] => [languageid] => [emailstamp] => [threadedmode] => [autosubscribe] => [pmtotal] => [pmunread] => [salt] => [ipoints] => [infractions] => [warnings] => [infractiongroupids] => [infractiongroupid] => [adminoptions] => [profilevisits] => [friendcount] => [friendreqcount] => [vmunreadcount] => [vmmoderatedcount] => [socgroupinvitecount] => [socgroupreqcount] => [pcunreadcount] => [pcmoderatedcount] => [gmmoderatedcount] => [assetposthash] => [fbuserid] => [fbjoindate] => [fbname] => [logintype] => [fbaccesstoken] => [newrepcount] => [vbseo_likes_in] => [vbseo_likes_out] => [vbseo_likes_unread] => [temp] => [field1] => [field2] => [field3] => [field4] => [field5] => [subfolders] => [pmfolders] => [buddylist] => [ignorelist] => [signature] => [searchprefs] => [rank] => [icontitle] => [iconpath] => [avatarpath] => [hascustomavatar] => 0 [avatardateline] => [avwidth] => [avheight] => [edit_userid] => [edit_username] => [edit_dateline] => [edit_reason] => [hashistory] => [pagetext_html] => [hasimages] => [signatureparsed] => [sighasimages] => [sigpic] => [sigpicdateline] => [sigpicwidth] => [sigpicheight] => [postcount] => 8 [islastshown] => [isfirstshown] => [attachments] => [allattachments] => ) --> Catching error in CFC - Coldfusion - Advanced Techniques

Catching error in CFC - Coldfusion - Advanced Techniques

Hello, I'm doing (it's juste th beginning) an application CFMX 7 + Fusebox 4.1 + MVC. I'm using some object, all works fine. No I'd like implement the error catching. I produce an error (voluntary). In one function of my CFC file, in SELECT, I make an error in the table name. I have this code : <cftry> <cffunction name="getlist" access="public" returntype="query" output="true"> ..... </cffunction> <cfcatch type="any"> <cfthrow message="#cfcatch.Message# <br> #cfcatch.Detail#"> </cfcatch> </cftry> When I execute, I have an "horrible" screen with that : The web site you are accessing has experienced an unexpected error. Please contact the website administrator. ...

Sponsored Links
  1. #1

    Default Catching error in CFC

    Hello,

    I'm doing (it's juste th beginning) an application CFMX 7 + Fusebox 4.1 + MVC.

    I'm using some object, all works fine. No I'd like implement the error
    catching. I produce an error (voluntary). In one function of my CFC file, in
    SELECT, I make an error in the table name.

    I have this code :
    <cftry>
    <cffunction name="getlist" access="public" returntype="query" output="true">
    .....
    </cffunction>

    <cfcatch type="any">
    <cfthrow message="#cfcatch.Message# <br> #cfcatch.Detail#">
    </cfcatch>
    </cftry>

    When I execute, I have an "horrible" screen with that :
    The web site you are accessing has experienced an unexpected error.
    Please contact the website administrator.

    The following information is meant for the website developer for debugging
    purposes.
    Error Occurred While Processing Request
    Error Executing Database Query.
    Table 'gfacturetest.t_use' doesn't exist

    Why I don't goin the cfcatch ?

    Thanks,





    Sponsored Links
    Oufti Guest

  2. #2

    Default Re: Catching error in CFC

    You need to put the try catch block inside the cffunction. You cannot do your error handling like this. CFCs do not execute in page order so all function logic must be inside the cffunction tags.
    Stressed_Simon Guest

  3. #3

    Default Re: Catching error in CFC

    Originally posted by: Stressed_Simon
    You need to put the try catch block inside the cffunction. You cannot do your
    error handling like this. CFCs do not execute in page order so all function
    logic must be inside the cffunction tags.

    Sorry but same result.

    Christian,



    Oufti Guest

  4. #4

    Default Re: Catching error in CFC

    Can you post your whole function?
    Stressed_Simon Guest

  5. #5

    Default Re: Catching error in CFC

    Originally posted by: Stressed_Simon
    Can you post your whole function?

    Sure :)

    Here you are :

    <cftry>
    <cffunction name="getlist" access="public" returntype="boolean"
    output="false">
    <cfargument name="order" required="no" type="string">

    <cfif isDefined("order")>

    <cfswitch expression="#order#">
    <cfcase value="asc,desc">
    <cfset _order = order>
    </cfcase>

    <cfdefaultcase>
    <cfif _order EQ "asc">
    <cfset _order = "desc">
    <cfelse>
    <cfset _order = "asc">
    </cfif>
    </cfdefaultcase>
    </cfswitch>

    </cfif>

    <cfquery name="getlist" datasource="#session.dsn#">
    SELECT * FROM T_USER
    ORDER BY #_orderby# #_order#
    </cfquery>

    <cfset _getlist = getlist>
    <cfreturn true>

    </cffunction>



    Oufti Guest

  6. #6

    Default Re: Catching error in CFC

    OK, I can't see any try and catch blocks in there? Also there is still a cftry
    tag outside the cffunction block?

    I suggest trying something like this:-



    <cffunction name="getlist" access="public" returntype="boolean" output="false">
    <cfargument name="order" required="no" type="string">

    <cfif isDefined("order")>

    <cfswitch expression="#order#">
    <cfcase value="asc,desc">
    <cfset _order = order>
    </cfcase>

    <cfdefaultcase>
    <cfif _order EQ "asc">
    <cfset _order = "desc">
    <cfelse>
    <cfset _order = "asc">
    </cfif>
    </cfdefaultcase>
    </cfswitch>

    </cfif>

    <cftry>
    <cfquery name="getlist" datasource="#session.dsn#">
    SELECT * FROM T_USER
    ORDER BY #_orderby# #_order#
    </cfquery>
    <cfcatch type="databaseError">
    <cfthrow message="#cfcatch.Message# <br> #cfcatch.Detail#">
    </cfcatch>
    </cftry>
    <cfset _getlist = getlist>
    <cfreturn true>

    </cffunction>

    Stressed_Simon Guest

  7. #7

    Default Re: Catching error in CFC

    Hello,

    I tried but same problem :(

    Christian,
    Oufti Guest

  8. #8

    Default Re: Catching error in CFC

    Are you actually catching the error? The cftry around the cfquery means it will
    throw the error to the cfcatch block, but the cfcatch block just uses cfthrow
    to throw the error. So it is still erroring. You need to catch the error at the
    point of invoking:-



    <!--- this is the invokation --->
    <cfscript>
    myObj = createObject("component", "myCFC");

    // catch errors
    try {
    bResult = myObj.getlist();
    }
    catch (databaseError cfcatch) {
    writeOutput(cfcatch.message);
    writeOutput(cfcatch.detail);
    }
    </cfscript>

    <!--- this is the function in the cfc --->
    <cffunction name="getlist" access="public" returntype="boolean" output="false">
    <cfargument name="order" required="no" type="string">

    <cfif isDefined("order")>

    <cfswitch expression="#order#">
    <cfcase value="asc,desc">
    <cfset _order = order>
    </cfcase>

    <cfdefaultcase>
    <cfif _order EQ "asc">
    <cfset _order = "desc">
    <cfelse>
    <cfset _order = "asc">
    </cfif>
    </cfdefaultcase>
    </cfswitch>

    </cfif>

    <cftry>
    <cfquery name="getlist" datasource="#session.dsn#">
    SELECT * FROM T_USER
    ORDER BY #_orderby# #_order#
    </cfquery>
    <cfcatch type="database">
    <cfthrow type="databaseError" message="#cfcatch.Message# <br>
    #cfcatch.Detail#">
    </cfcatch>
    </cftry>
    <cfset _getlist = getlist>
    <cfreturn true>

    </cffunction>

    Stressed_Simon Guest

  9. #9

    Default Re: Catching error in CFC

    Thanks a lot Stressed_Simon that's work fine :)

    Christian,
    Oufti Guest

Similar Threads

  1. Help: Catching a bad url error when loading an XMLobject?
    By ChrisRauh in forum Macromedia Flash Data Integration
    Replies: 1
    Last Post: August 9th, 07:38 PM
  2. Cold Fusion 404 Error Catching
    By solosier2 in forum Coldfusion - Advanced Techniques
    Replies: 1
    Last Post: June 6th, 06:17 AM
  3. Error catching script
    By James in forum PHP Development
    Replies: 2
    Last Post: October 8th, 03:46 PM
  4. Catching Apache error with a Perl script
    By PapaBear in forum PERL Miscellaneous
    Replies: 2
    Last Post: August 20th, 12:56 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •