This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<body> | |
<button id="btn">Connect</button> | |
<script> | |
const btn = document.getElementById('btn'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
</head> | |
<body> | |
<button id="btn">OI</button> | |
<script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addEventListener('fetch', event => { | |
event.respondWith(handleRequest(event.request)) | |
}); | |
async function handleRequest(request) { | |
// Any logic you want | |
return fetch(request); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function thisThrows() { | |
throw new Error("Thrown from thisThrows()"); | |
} | |
function myFunctionThatCatches() { | |
try { | |
return thisThrows(); | |
} catch (e) { | |
// Maybe do something else here first. | |
throw e; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function thisThrows() { | |
throw new Error("Thrown from thisThrows()"); | |
} | |
function myFunctionThatCatches() { | |
try { | |
return thisThrows(); | |
} catch (e) { | |
throw new TypeError(e.message); | |
} finally { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function thisThrows() { | |
throw new Error("Thrown from thisThrows()"); | |
} | |
async function myFunctionThatCatches() { | |
try { | |
return thisThrows(); | |
} catch (e) { | |
console.error(e); | |
} finally { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function thisThrows() { | |
throw new Error("Thrown from thisThrows()"); | |
} | |
async function run() { | |
try { | |
await thisThrows(); | |
} catch (e) { | |
console.error(e); | |
} finally { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function thisThrows() { | |
throw new Error("Thrown from thisThrows()"); | |
} | |
try { | |
thisThrows(); | |
} catch (e) { | |
console.error(e); | |
} finally { | |
console.log('We do cleanup here'); |