The cfthrow
tag raises a developer-specified exception that can be caught with cfcatch
tag having any of the following type specifications:
cfcatch type = "custom_type"
cfcatch type = "Application"
cfcatch type = "Any"
<cfthrow type = "exception_type " message = "message" detail = "detail_description " errorCode = "error_code " extendedInfo = "additional_information ">
cferror,
cfrethrow,
cftry cfcatch
Use cfthrow
within a cftry
block to raise an error condition. The cfcatch
block can access any accompanying information as follows:
cfcatch
.message
cfcatch
.detail cfcatch
.errorcode. cfcatch.tagContext
. tagContext captures the context of the exception; that is, the name and position of each tag in the tag stack, and the full pathnames of the files that contain the tags in the tag stack.
Note To see the information displayed by |
<!--- 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>