xxxxxxxxxx
try {
// body of try
throw exception;
}
catch(error) {
// body of catch
}
xxxxxxxxxx
try {
throw new Error('Whoops!')
} catch (e) {
console.error(e.name + ': ' + e.message)
}
xxxxxxxxxx
throw new Error("Error message here"); // Uncaught Error: Error message here
xxxxxxxxxx
throw 'Error2'; // generates an exception with a string value
throw 42; // generates an exception with the value 42
throw true; // generates an exception with the value true
throw new Error('Required'); // generates an error object with the message of Required