The CFTHROW tag raises a developer-specified exception that can be caught with CFCATCH tag having any of the following type specifications:
<CFTHROW TYPE= "exception_type " MESSAGE="message" DETAIL= "detail_description " ERRORCODE= "error_code " EXTENDEDINFO= "additional_information ">
Optional. A custom type or the predefined type APPLICATION. None of the other predefined types should be specified because these types are not generated by ColdFusion applications. If you specify the exception type APPLICATION, you need not specify a type for CFCATCH, because the APPLICATION type is the default CFCATCH type.
Optional. A message that describes the exceptional event.
Optional. A detailed description of the event. The ColdFusion server appends the position of the error to this description; the server uses this parameter if an error is not caught by your code.
Optional. A custom error code that you supply.
Optional. A custom error code that you supply.
Use CFTHROW within a CFTRY block to raise an error condition.The CFCATCH block can access any accompanying information as follows:
Note | In order to see the information displayed by TagContext, use the ColdFusion Administrator to enable the CFML stack trace.Under Debugging in the ColdFusion Administrator, choose the checkbox next to "Enable CFML stack trace. " |
<!--- This example shows the use of CFTHROW. ---> <HTML> <HEAD> <TITLE> CFTHROW Example </TITLE> </HEAD> <BASEFONT FACE="Arial, Helvetica" SIZE=2> <BODY bgcolor="#FFFFD5"> <H3>CFTHROW Example</H3> <!--- open a CFTRY block ---> <CFTRY> <!--- define a condition upon which to throw the error ---> <CFIF NOT IsDefined("URL.myID")> <!--- throw the error ---> <CFTHROW MESSAGE="ID is not defined"> </CFIF> <!--- perform the error catch ---> <CFCATCH TYPE="application"> <!--- display your message ---> <H3>You've Thrown an <B>Error</B></H3> <CFOUTPUT> <!--- and the diagnostic feedback from the application server ---> <P>#CFCATCH.message#</P> <P>The contents of the tag stack are:</P> <CFLOOP index=i from=1 to = #ArrayLen(CFCATCH.TAGCONTEXT)#> <CFSET sCurrent = #CFCATCH.TAGCONTEXT[i]#> <BR>#i# #sCurrent["ID"]# (#sCurrent["LINE"]#,#sCurrent["COLUMN"]#) #sCurrent["TEMPLATE"]# </CFLOOP> </CFOUTPUT> </CFCATCH> </CFTRY> </BODY> </HTML>