Created
August 21, 2020 14:20
-
-
Save roychri/ae684e50d523cc4ea95d52fdb5bc1803 to your computer and use it in GitHub Desktop.
How async function react to Throw
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 otherFunctionResolve() { | |
return Promise.resolve(); | |
} | |
function otherFunctionReject() { | |
return Promise.reject(); | |
} | |
function otherFunctionThrow() { | |
throw new Error("oops"); | |
} | |
function doSomethingResolve() { | |
return otherFunctionResolve(); | |
} | |
function doSomethingReject() { | |
return otherFunctionReject(); | |
} | |
function doSomethingThrow() { | |
return otherFunctionThrow(); | |
} | |
async function doSomethingThrowAsync() { | |
return otherFunctionThrow(); | |
} | |
doSomethingResolve().then( () => console.log("PASSED") ).catch( () => console.log("FAILED") ); | |
doSomethingReject().then( () => console.log("FAILED") ).catch( () => console.log("PASSED") ); | |
try { | |
doSomethingThrow().then( () => console.log("FAILED") ).catch( () => console.log("FAILED") ); | |
} catch ( err ) { | |
console.log("PASSED"); | |
} | |
doSomethingThrowAsync().then( () => console.log("FAILED") ).catch( () => console.log("PASSED") ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment