Spec-Zone.ru › ColdFusion

cfcatch

Used inside a cftry tag. Together, they catch and process exceptions in CFML pages. Exceptions are events that disrupt the normal flow of instructions in a CFML page, such as failed database operations, missing include files, and developer-specified events.

<cfcatch>

catch (any e) { }

  • CF4+
  • Lucee
  • See Also: cftry cffinally

    Attribute Reference

    name string

    Variable name for cfcatch expression.

    type string
    Default: any

    application: catches application exceptionsdatabase: catches database exceptionstemplate: catches ColdFusion page exceptionssecurity: catches security exceptionsobject: catches object exceptionsmissingInclude: catches missing include file exceptionsexpression: catches expression exceptionslock: catches lock exceptionscustom_type: catches the specified custom exception type that is defined in a cfthrow tag java.lang.Exception: catches Java object exceptions searchengine: catches Verity search engine exceptions any: catches all exception types
    Values:
    • application
    • database
    • template
    • security
    • object
    • missinginclude
    • expression
    • lock
    • custom_type
    • searchengine
    • any

    Examples
    Sample code using the cfcatch tag

    A simple try/catch script based example

    Create a divide by zero error and then catch it.

    try {
        x = 5/0;
    }
    catch (any e) {
        writeOutput("Error: " & e.message);
    }

    Expected Result: Error: Division by zero.

    A simple try/catch tag based example

    Create a divide by zero error and then catch it.

    <cftry>
        <cfset x = 5/0 />
        <cfcatch type="any">
            Error: <cfoutput>#cfcatch.message#</cfoutput>
        </cfcatch>
    </cftry>

    Expected Result: Error: Division by zero.

    © 2012–present Foundeo, Inc. and the CFDocs contributors.
    Licensed under the MIT License.
    ColdFusion is a trademark of Adobe Systems Incorporated.
    https://cfdocs.org/cfcatch

    Spec-Zone.ru

    Настройки Оффлайн Что нового Помощь О нас
    Spec-Zone .ru
    спецификации, руководства, описания, API