Skip to content

Instantly share code, notes, and snippets.

View SegersIan's full-sized avatar

Segers Ian SegersIan

View GitHub Profile
<!DOCTYPE html>
<html lang="en">
<body>
<button id="btn">Connect</button>
<script>
const btn = document.getElementById('btn');
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<button id="btn">OI</button>
<script>
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
});
async function handleRequest(request) {
// Any logic you want
return fetch(request);
}
function thisThrows() {
throw new Error("Thrown from thisThrows()");
}
function myFunctionThatCatches() {
try {
return thisThrows();
} catch (e) {
// Maybe do something else here first.
throw e;
function thisThrows() {
throw new Error("Thrown from thisThrows()");
}
function myFunctionThatCatches() {
try {
return thisThrows();
} catch (e) {
throw new TypeError(e.message);
} finally {
async function thisThrows() {
throw new Error("Thrown from thisThrows()");
}
async function myFunctionThatCatches() {
try {
return await thisThrows(); // <-- Notice we added here the "await" keyword.
} catch (e) {
console.error(e);
} finally {
async function thisThrows() {
throw new Error("Thrown from thisThrows()");
}
async function myFunctionThatCatches() {
try {
return thisThrows();
} catch (e) {
console.error(e);
} finally {
async function thisThrows() {
throw new Error("Thrown from thisThrows()");
}
thisThrows()
.catch(console.error)
.then(() => console.log('We do cleanup here'));
// Output:
// Error: Thrown from thisThrows()
async function thisThrows() {
throw new Error("Thrown from thisThrows()");
}
async function run() {
try {
await thisThrows();
} catch (e) {
console.error(e);
} finally {
async function thisThrows() {
throw new Error("Thrown from thisThrows()");
}
try {
thisThrows();
} catch (e) {
console.error(e);
} finally {
console.log('We do cleanup here');