Throw()

Throws a developer-specified exception, which can be caught with a <cfcatch> tag

Throw( message=string, type=string, detail=string, errorcode=string, extendedInfo=string, object=any, cause=any );

Returns: void

Argument Description
message
string, optional

Message that describes exception event.

type
string, optional
  • A custom type
  • Application Do not enter another predefined type; types are not generated by CFML applications. If you specify Application, you need not specify a type for cfcatch.
detail
string, optional

Additional detail about the exception.

Often used for more sensitive information, i.e. which you may choose not to display to end users

errorcode
string, optional

A custom error code that you supply.

extendedInfo
string, optional

Extended information about the exception.

object
any, optional

Throws a Java exception from a CFML tag.

This attribute is mutually exclusive with all other arguments of this function.

cause
any, optional

The cause of the exception created with this tag. This can be a cfcatch block or a native java exception.

Examples

// thrown as a statement example
	try {
		throw "thrown";
	} catch (e){
		dump(var=cfcatch, label="single argument keyword");
	}
<span class="o">/*</span> <span class="nv">this</span> <span class="nv">won</span><span class="err">&#39;</span><span class="nv">t</span> <span class="nv">work</span> <span class="nv">as</span> <span class="nv">expected</span><span class="p">,</span> <span class="nv">because</span> <span class="nv">thrown</span> <span class="nv">expects</span> <span class="nv">only</span> <span class="nv">a</span> <span class="nv">single</span>
    <span class="nv">argument</span> <span class="nv">function</span> <span class="nv">in</span> <span class="nv">cfscript</span><span class="p">,</span> <span class="nv">only</span> <span class="nv">message</span> <span class="nv">will</span> <span class="nv">be</span> <span class="nv">populated</span>
 <span class="nv">see</span> <span class="nv">https</span><span class="p">:</span><span class="c">//luceeserver.atlassian.net/browse/LDEV-2832</span>
<span class="o">*/</span>
<span class="nv">try</span> <span class="p">{</span>
	<span class="nv">throw</span> <span class="nv">message</span><span class="o">=</span><span class="s2">&quot;thrown&quot;</span>
		<span class="nv">detail</span><span class="o">=</span><span class="s2">&quot;deets&quot;</span>
		<span class="nv">errorCode</span><span class="o">=</span><span class="s2">&quot;403&quot;</span>
		<span class="nv">type</span><span class="o">=</span><span class="s2">&quot;Test&quot;</span><span class="p">;</span>
<span class="p">}</span> <span class="nf">catch</span> <span class="p">(</span><span class="nv">e</span><span class="p">){</span>
	<span class="nf">dump</span><span class="p">(</span><span class="k">var</span><span class="o">=</span><span class="nv">cfcatch</span><span class="p">,</span> <span class="nv">label</span><span class="o">=</span><span class="s2">&quot;additional arguments are ignored&quot;</span><span class="p">);</span>
<span class="p">}</span>
<span class="c">// use this syntax instead</span>
<span class="nv">try</span> <span class="p">{</span>
	<span class="nf">throw</span> <span class="p">(</span><span class="nv">message</span><span class="o">=</span><span class="s2">&quot;thrown&quot;</span><span class="p">,</span>
		<span class="nv">detail</span><span class="o">=</span><span class="s2">&quot;deets&quot;</span><span class="p">,</span>
		<span class="nv">errorCode</span><span class="o">=</span><span class="s2">&quot;403&quot;</span><span class="p">,</span>
		<span class="nv">type</span><span class="o">=</span><span class="s2">&quot;Test&quot;</span><span class="p">);</span>
<span class="p">}</span> <span class="nf">catch</span> <span class="p">(</span><span class="nv">e</span><span class="p">){</span>
	<span class="nf">dump</span><span class="p">(</span><span class="k">var</span><span class="o">=</span><span class="nv">cfcatch</span><span class="p">,</span> <span class="nv">label</span><span class="o">=</span><span class="s2">&quot;script throw with arguments&quot;</span><span class="p">);</span>
<span class="p">}</span>

See also