try {
    let result = 10 / 0;
    console.log(result);
} catch (error) {
    console.error("Error caught:", error);
}
async function fetchData() {
    try {
        let response = await fetch("<https://api.example.com/data>");
        let data = await response.json();
        console.log(data);
    } catch (error) {
        console.error("Error fetching data:", error);
    }
}
fetchData();
try {
    setTimeout(() => {
        throw new Error("This error won't be caught");
    }, 1000);
} catch (error) {
    console.error("Caught error:", error); // ❌ This will not work!
}
// Use try...catch inside the callback
setTimeout(() => {
    try {
        throw new Error("This error is caught!");
    } catch (error) {
        console.error("Caught error:", error);
    }
}, 1000);

// Or use Promise-based error handling
function delayedTask() {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            reject(new Error("Promise rejection"));
        }, 1000);
    });
}
delayedTask().catch(error => console.error("Caught error:", error));