const a = 5
try {
console.log(b) // b is not defined, so throws an error
} catch (err) {
console.error(err) // will log the error with the error stack
}
console.log(a) // still gets executed
try {
throw Error('This error will get caught');
} catch (e) {
console.log(e);
}
// Prints: This error will get caught
console.log('The thrown error that was caught in the try...catch statement!');
// Prints: 'The thrown error that was caught in the try...catch statement!'
const someVar = 'Cannot be reassigned';
try {
someVar = 'Still going to try';
} catch(e) {
console.log(e);
}
// Prints: TypeError: Assignment to constant variable.