Javascript Reference
Categories: throw

javascript throw Description

@March 15, 2008, 1:22 a.m.
throwFirefox/Netscape/NN 6 IE 5 ECMA 3

Triggers an exception condition, passing a value along with the exception. Although the value you pass can be a simple string, ideally you should pass an instance of the JavaScript Error object filled with sufficient information for a catch statement to act intelligently on the error. A throw statement must be enclosed in the try portion of a try-catch construction.

function processNumber(inputField) {
    try {
        var inpVal = parseInt(inputField.value, 10);
        if (isNaN(inpVal)) {
            var msg = "Please enter a number only.";
            var err = new Error(msg);
            if (!err.message) {
                err.message = msg;
            throw err;
        // process number
    catch (e) {
        inputField.focus( ); );

Powered by Linode.