Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 426473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:28:58+00:00 2026-05-12T19:28:58+00:00

I have a Function in CFC file, which will be called from .cfm file

  • 0

I have a Function in CFC file, which will be called from .cfm file like below

 <cffunction name="cftest" access="public" returntype="query" output="true" hint="Function returns Records">

      <cfquery name="qryTest" datasource="DBTest">
                select * from emp_tab;
       </cfquery>

    <cfreturn selectRecordsResultSet />

 </cffunction>

How can I handle DB Exception using cftry? as this is returning Query, Is it possible to catch the DB Exception and pass the Details to the other page from where it is called?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T19:28:59+00:00Added an answer on May 12, 2026 at 7:28 pm

    Here is an example of my usual implementation of this:

    <cffunction name="getCurrentRecordsCount" access="public" output="false" returntype="any" hint="Get total history records count">
        <cfargument name="filters" type="struct" required="false" default="#StructNew()#" hint="Filtering rules">
        <cfset var qGetRecordCount = "" />
        <cftry>
    
            <cfquery datasource="#variables.dsn#" name="qGetRecordCount">
                SELECT COUNT(*) AS cnt FROM ....
            </cfquery>
    
            <cfreturn qGetRecordCount.cnt />
    
        <cfcatch type="any">
            <cfreturn error(cfcatch.message, cfcatch.detail) />
        </cfcatch>
        </cftry>
    </cffunction>
    

    If you want to handle only database errors, change type to the database.

    Errors handling and reporting performed using these three methods:

    <cffunction name="error" access="private" output="false" returntype="boolean" hint="Set error status and message">
        <cfargument name="message" type="string" required="true" hint="Error message text" />
        <cfargument name="detail" type="string" required="false" default="" hint="Error detail text" />
        <cfset variables.fError = true />
        <cfset variables.fErrorText = arguments.message />
        <cfif Len(arguments.detail)>
            <cfset variables.fErrorText = variables.fErrorText & " [" & arguments.detail & "]" />
        </cfif>
        <cfreturn false />
    </cffunction>
    
    <cffunction name="gotError" access="public" output="false" returntype="boolean" hint="Return latest error flag state">
        <cfreturn variables.fError />
    </cffunction>
    
    <cffunction name="getError" access="public" output="false" returntype="string" hint="Return latest error text and reset the flag">
        <cfset var txt = variables.fErrorText />
        <cfset variables.fError = false />
        <cfset variables.fErrorText = "" />
        <cfreturn txt />
    </cffunction>
    

    Please note that for methods with returntype=”void” I use cfset instead of cfreturn:

    <cfset error(cfcatch.message, cfcatch.detail) />
    

    So in code I can do the following (cfscript):

    // calculate filtered records count
    totalLogCount = request.loggingService.getCurrentRecordsCount(filters);
    
    // check if error was thrown
    if (request.loggingService.gotError()) {
       // report the error details somehow
       WriteOutput(request.loggingService.getError());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 208k
  • Answers 208k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There are three reasons why a Java program can crash:… May 12, 2026 at 9:35 pm
  • Editorial Team
    Editorial Team added an answer You can't make socket connections on App Engine - only… May 12, 2026 at 9:35 pm
  • Editorial Team
    Editorial Team added an answer You are probably using Visual Studio 2010 (this is where… May 12, 2026 at 9:34 pm

Related Questions

I am reorganizing my ColdFusion directory structures and am curious about how experienced CF
One of the great features of CFCs is the ability to reuse the code
In a ColdFusion Component (CFC), is it necessary to use fully qualified names for
I have built a CFC designed to serve as a dynamic, aging cache intended
Normally you create a function using cfscript like: <cfscript> function foo() { return bar;

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.