<cfrethrow>

Description

Rethrows the currently active exception. Preserves the exception's cfcatch.type and cfcatch.tagContext information.

Category

Exception handling tags

See also

cferror, cfthrow, cftry cfcatch

Usage

Use the cfrethrow tag within a cfcatch block. This tag is useful in error handling code when the error handler is not designed to handle an error that it catches. For example, if cfcatch type = "any" gets a DATABASE exception and the code is designed only to handle CFX exceptions, the handler should re-raise the original exception with details intact, so that a higher-level handler can process the error information. If you used cfthrow in this case, you would lose the type and relevant details of the original exception.

Example

<!--- This example shows the use of cfrethrow --->
<html>
<head>
<title>cfrethrow Example</title>
</head>

<BASEFONT face = "Arial, Helvetica" size = 2>
<body bgcolor = "#FFFFD5">

<H3>cfrethrow Example</H3>

<!--- Rethrow a DATABASE exception. --->

<cftry>
    <cftry>
        <cfquery name = "GetMessages" dataSource = "cfsnippets">
            SELECT  *
            FROM   Messages
        </cfquery>
    <cfcatch type = "DATABASE">
        <!----------------------------------------------------------- 
        If the database signalled a 50555 error, we can ignore it, 
        otherwise rethrow the exception. 
        ------------------------------------------------------------->
        <cfif cfcatch.sqlstate neq 50555>
            <cfrethrow>
        </cfif>
    </cfcatch>
    </cftry>
    
<cfcatch>
    <h3>Sorry, this request can't be completed</h3>
    <h4>Catch variables</h4>
    <cfoutput>
        <cfloop collection = #cfcatch# item = "c">
            <br><cfif IsSimpleValue(cfcatch[c])>#c# = #cfcatch[c]#</cfif>
        </cfloop>
    </cfoutput>
</cfcatch>
</cftry>
  
</body>
</html>