1 Reply Latest reply on Feb 17, 2007 7:04 AM by BKBK

    cferror doesn't process

    |mantra| Level 1
      can anyone tell me if there's anything wrong with this code : ( the bb is set wrong to throw the error )

      <cffunction name="onRequestStart" returntype="void" output="true">
      <cfset request.dsn = "codelib">
      <cfset request.dbp = "">
      <cfset request.dbu = "">
      <cfinclude template="header.cfm">
      <cftry>
      <cfquery name="qDatabase" datasource="#request.dsn#" maxrows="1">
      SELECT bb
      FROM genericdata
      </cfquery>
      <cfcatch type="database">
      <cferror type="exception" mailto="#admin_email#" template="error.cfm">
      </cfcatch>
      </cftry>
      </cffunction>

      i never get the error.cfm page . The query fails and it just goes displays the page anyway with header and footer. it's as though it's not being caught or something. I've tried with both type="exception" and "request"

      Thx
        • 1. cferror doesn't process
          BKBK Adobe Community Professional & MVP
          > i never get the error.cfm page .

          'Course, you don't. There are 2 reasons.

          One, when an exception occurs, the try/catch mechanism and the onError() event override the cferror tag, in that order.

          Second, the cferror tag only registers an error that occurs after the tag. Hence the general advice to let Coldfusion read the tag as early as possible during a request.

          Putting the two together, you can see why you get the result you get. The error in the query causes execution to move into the cfcatch block. However, still within the cfcatch block, there is no code after the cferror tag, hence no exception for the cferror tag to handle.

          If you comment out the onError method and use the following code, Coldfusion will take you to the error.cfm page. Nevertheless, I cannot think of a reason why you would want to handle errors in this way.

          <cftry>

          <cfthrow>

          <cfcatch type="any">

          <cferror type="exception" mailto="#admin_email#" template="error.cfm">

          <cfquery name="qDatabase" datasource="#request.dsn#" maxrows="1">
          SELECT bb
          FROM genericdata
          </cfquery>

          </cfcatch>

          </cftry>