Exception Handling
try {
throw new Error('Something bad happened');
}
catch(e) {
console.log(e);
}Error Sub Types
RangeError
// Call console with too many arguments
console.log.apply(console, new Array(1000000000)); // RangeError: Invalid array lengthReferenceError
'use strict';
console.log(notValidVar); // ReferenceError: notValidVar is not definedSyntaxError
TypeError
URIError
Always use Error
ErrorYou don't have to throw an error
throw an errorExceptional cases
Unclear where it is thrown
Makes graceful handling hard
Not well represented in the type system
Last updated