CONCEPTS
01Try, catch, finally
02Throwing custom errors
03Error objects (name, message, stack)
04Syntax vs Runtime errors
05Debugging with console
06Window.onerror
SYNTAX_DEMO
Managing failures gracefully
function divide(a, b) {
if (b === 0) {
throw new Error("Cannot divide by zero");
}
return a / b;
}
try {
console.log(divide(10, 0));
} catch (error) {
console.error("Caught an error:", error.message);
} finally {
console.log("Cleanup code executes here.");
}