Use a try-catch statement when code may fail, such as server communication, null-property access, or a third-party function that throws. The try block encloses unsafe code; catch receives an Error object with details and provides a place to recover. section 5.1
Handling a missing student
Calling findStudent with an unknown identifier can throw an exception. Wrapping the call lets the program report the error instead of stopping without handling it. section 5.1
try {
// code that might throw an exception in here
}
catch (e) {
// statements to handle any exceptions
console.log('ERROR' + e.message);
}
A minimal structure separates risky code from the statements that handle its exception. section 5.1
Imperative try-catch handling becomes difficult when errors must be abstracted, composed, or chained. Throwing also creates an additional exit path, conflicting with predictable functional design. section 5.1









