To demonstrate error handling in a Node.js application.
Error handling is used to detect and handle errors without stopping the entire application.
try {
let result = 10 / 0;
if (!isFinite(result)) {
throw new Error("Invalid calculation");
}
console.log(result);
}
catch (error) {
console.log("Error:", error.message);
}