View comments | RSS feed

cfthrow

Description

Throws a developer-specified exception, which can be caught with a cfcatch tag that has any of the following type attribute options:

Category

Exception handling tags, Flow-control tags

Syntax 1

<cfthrow 
  type = "exception_type "
  message = "message"
  detail = "detail_description "
  errorCode = "error_code "
  extendedInfo = "additional_information"
  object = "java_except_object">

Syntax 2

<cfthrow 
  object = #object_name#>

See also

cferror, cfrethrow, cftry

History

New in ColdFusion MX: this tag can throw ColdFusion component method exceptions.

Attributes

Attribute Req/Opt Default Description
type
Optional
Application
  • A custom type
  • Application
Do not enter another predefined type; types are not generated by ColdFusion applications. If you specify Application, you need not specify a type for cfcatch.
message
Optional

Message that describes exception event.
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 code that you supply.
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.

Usage

Use this tag within a cftry block, to throw an error. The cfcatch block can access accompanying information, as follows:

To get more information, use cfcatch.tagContext. This shows where control switches from one page to another in the tag stack (for example, cfinclude, cfmodule).

To display the information displayed by tagContext: in the ColdFusion Administrator, Debugging page, select Enable CFML Stack Trace.

To use this tag with the object parameter, you must define an exception using the cfobject tag, with code such as the following:

<cfobject 
type="java" 
action="create" 
class="coldfusion.tagext.InvalidTagAttributeException" 
name="obj">
<cfset obj.init("Attribute", "value")>

With this code, the cfthrow statement would be as follows:

<cfthrow object=#obj#>

The cfthrow tag passes exception parameters to the obj variable.

Example

<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>

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6

Comments are no longer accepted for ColdFusion MX. ColdFusion 8 is the current version.

Comments


aoibheil said on Sep 10, 2002 at 9:07 PM :
The "ID" in the above example from the cfcatch.tagContext:

#i# #sCurrent["ID"]#

Will occasionally throw a java exception.

Element ID is undefined in a Java object of type class coldfusion.util.FastHashtable referenced as
The error occurred on line 323.

I do not know what causes this and I use this catch a lot in debugging.
hlichtin said on Mar 11, 2003 at 10:32 AM :
We cannot reproduce this problem. Any reports of this happening, with details of the circumstances including OS, web server, CF version (updaters, etc.) would be appreciated.
Cfsaravan said on Oct 14, 2003 at 3:25 PM :
I am not able to loop through an array,using the start element 1 in the cfloop
eg:
<cfloop start=1 end=#len(arr_lookupcategories#)>

It gives me Element 1 is undefined in a Java object of type class coldfusion.runtime.Array referenced as
jeffiel said on Apr 1, 2004 at 1:54 AM :
I am getting this error as well:

"Element ID is undefined in a Java object of type class coldfusion.util.FastHashtable referenced as "

The line of code it seems to indicate causes it is:

<cfinclude template="login_includes/#getFirstTimers.login_include_file#">

CFMX 6.1
Linux (RH 9)

-jeff
ajays said on Aug 27, 2004 at 8:17 AM :
I am getting similar error. We can't reproduce this error.
The requested circuit ' Search' is undefined for this application.

The error occurred while processing an element with a general identifier of (CFTHROW), occupying document position
(204:3) to (204:136).

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/Tags-pt313.htm