本文档基于 CC协议(Creative Commons Share-Alike License)发布,是developer.mozilla.com, www.mozref.comwww.aptana.com共同劳动的成果。

throw

Specifies an exception to throw when an error occurs.

Syntax

throw expression; 

Example


function getQuantity(orderQuantity) {
   if (orderQuantity < 0) throw new Error("orderQuantity cannot be negative!");
   
   ... //more statements
}