JSFiddle - React, Tailwind, and code Playground

by Retsam19

JavaScript

const delay = (t) => new Promise(resolve => setTimeout(resolve, t))

const somePromise = async () => {
    await delay(500);
    throw new Error("Error");
}

const example1 = async () => {
     const p = somePromise();
     p.catch(e => console.log("Got error", e))
     await p;
}

const example2 = async () => {
     const p = somePromise()
         .catch(e => console.log("Got error", e))
     await p;
}

window.addEventListener("unhandledrejection", ({error: e}) => {
	console.log("Unhandled rejection", e);
});

example1();