A function equivalent of the cfthrow tag and is used in the <cfscript> mode.


Same as the <cfthrow> tag.


Exception handling functionsData output functions

Function syntax

For name=value pair:

throw (message = "message", type = "exception type", detail, errorCode = "error code", extendedInfo = "additional info", object = "java exception object")

For positional notations, the sequence must be followed exactly in the same manner as provided in the syntax. If you do not provide one of the attributes, use an empty string instead.


ColdFusion 11: Parameters passed to this function needs to be in a comma-separated format.

ColdFusion 9: Added this function.

See also



You can call this function by passing arguments as name=value pair or as positional arguments. For positional notations, specify the arguments in the sequence mentioned in the function syntax.


function TotalInterest(principal, annualRate, months) 
{ var years = 0; 
var interestRate = 0; 
var totalInterest = 0; 
principal = REReplace(trim(principal), "[\$]", "", "ALL"); 
annualRate = Replace(trim(annualRate), "%", "", "ALL"); 

if ((principal <= 0) OR (annualRate <= 0) OR (months <= 0)) { 
Throw(type="InvalidData",message="All values must be greater than 0."); 

//Use of Throw function in cfscript 
interestRate = annualRate / 100; 
years = months / 12; 
totalInterest = principal * (((1 + interestRate) ^ years) - 1); 
return DollarFormat(totalInterest); 

try { 
WriteOutput(TotalInterest("$2500.00", "5.5%", "12")); 
} catch(InvalidData ex) { 
//Displayig exception details on screen 
WriteOutput("<p>An InvalidData exception was thrown.</p>"); 

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy