/* * Force each of the follow error types to occur * and catch them. Log a message describing each * of the error types. * * Error types: * -SyntaxError (already done) * -ReferenceError * -TypeError * -RangeError * * Additionally, throw your own error with a * custom error message containing your name. * Catch your error and log a message.
JavaScript: Modify the provided JS file to force each of the JS error types to occur. Catch each error and log a message detailing which error type you triggered.
/*
* Force each of the follow error types to occur
* and catch them. Log a message describing each
* of the error types.
*
* Error types:
* -SyntaxError (already done)
* -ReferenceError
* -TypeError
* -RangeError
*
* Additionally, throw your own error with a
* custom error message containing your name.
* Catch your error and log a message.
*/
console.log('
try {
JSON.parse(`{name: 'John', age: 18}`);
} catch(error) {
console.log(`Caught a syntax error: `);
console.log(error);
}
// CODE STARTS HERE
// CODE ENDS HERE
console.log('PROGRAM END');
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images