Created
October 16, 2019 21:13
-
-
Save overra/3383166a44c6fe7f6e0c0771ac525b0a to your computer and use it in GitHub Desktop.
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
module.exports = function () { | |
return Promise.reject(new Error("Whoops")) | |
} |
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
const bar = require('./bar') | |
async function foo() { | |
return await bar(); | |
} | |
async function doFoo() { | |
const fooBar = await foo(); | |
return fooBar; | |
} | |
function foo2() { | |
return bar(); | |
} | |
async function doFoo2() { | |
const fooBar = await foo2(); | |
return fooBar | |
} | |
doFoo() | |
.then(res => console.log(res)) | |
.catch(err => console.error(err)) | |
doFoo2() | |
.then(res => console.log(res)) | |
.catch(err => console.error(err)) |
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
const bar = require('./bar') | |
async function foo1() { | |
try { | |
await (() => bar())() | |
} catch (err) { | |
console.log(err) | |
} | |
} | |
async function foo2() { | |
try { | |
await (async () => await bar())() | |
} catch (err) { | |
console.log(err) | |
} | |
} | |
foo1() | |
foo2() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment