Error Handling
1. The TRY … CATCH Statement
try {
// Code that may throw an error
} catch (error) {
// Code to handle the error
}try {
let result = 10 / 0;
console.log(result); // Infinity
let data = JSON.parse('{"name": "John"'); // Missing closing brace
} catch (error) {
console.log("An error occurred: " + error.message);
}2. The FINALLY Block
3. Throwing Custom Errors
4. Error Object Properties
5. Handling Different Types of Errors
Help us improve the content 🤩
Last updated