LANGUAGE » JAVASCRIPT
Exception
Error
To raise a generic error (exception):
js
throw new Error('Something is wrong!');
Try...catch...finally
See throw, try...catch documentation.
js
try {
throw new Error('Something is wrong!');
} catch (error) {
console.log(error.message);
if (error instanceof TypeError) {
// Handle TypeError
} else if (error instanceof RangeError) {
// Handle RangeError
} else if (error instanceof EvalError) {
// Handle EvalError
} else {
throw error;
}
} finally {
// Will always run
}