Try and Catch

try {var address2 = new Address("Superstreet 1", "no idea", "smalltown"); 
} catch (e) { 
console.log(e.message); //postalCode seems to be invalid! 
} 

Conditional catch clauses.

try {
    myroutine(); // may throw three types of exceptions
} catch (e) {
    if (e instanceof TypeError) {
        // statements to handle TypeError exceptions
    } else if (e instanceof RangeError) {
        // statements to handle RangeError exceptions
    } else if (e instanceof EvalError) {
        // statements to handle EvalError exceptions
    } else {
       // statements to handle any unspecified exceptions
       logMyErrors(e); // pass exception object to error handler
    }
}

Add your comment