Whatever message this page gives is out now! Go check it out!
<cfthrow
message = "message"
type = "exception type"
detail = "detail description"
errorCode = "error code"
extendedInfo = "additional information"
object = "java except object">
OR
<cfthrow
object = #object_name#>Attribute | Req/Opt | Default | Description |
detail | Optional | Description of the event. ColdFusion appends error position to description ; server uses this parameter if an error is not caught by your code. | |
errorCode | Optional | A custom error code that you supply. | |
extendedInfo | Optional | A custom error information that you supply. | |
message | Optional | Message that describes exception event. | |
object | Optional | Requires the value of the cfobject tag name attribute. Throws a Java exception from a CFML tag. This attribute is mutually exclusive with all other attributes of this tag. | |
type | Optional | Application |
|
<cfthrow
type="java"
action="create"
class="myException"
name="obj"><cfset obj.init("You must save your work before preceding")><cfthrow object=#obj#><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><cffunction name="getEmp">
<cfargument name="lastName" required="yes">
<cfquery name="empQuery" datasource="cfdocexamples" >
SELECT LASTNAME, FIRSTNAME, EMAIL
FROM tblEmployees
WHERE LASTNAME LIKE '#arguments.lastName#'
</cfquery>
<cfif empQuery.recordcount LT 1>
<cfthrow type="noQueryResult"
message="No results were found. Please try again.">
<cfelse>
<cfreturn empQuery>
</cfif>
</cffunction>
</cfcomponent>