Created
April 17, 2019 13:04
-
-
Save SegersIan/87dfa51c4a2eff64fd0c7b9a3d2bda87 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
function thisThrows() { | |
throw new Error("Thrown from thisThrows()"); | |
} | |
function myFunctionThatCatches() { | |
try { | |
return thisThrows(); | |
} catch (e) { | |
// Maybe do something else here first. | |
throw e; | |
} finally { | |
console.log('We do cleanup here'); | |
} | |
} | |
async function run() { | |
try { | |
await myFunctionThatCatches(); | |
} catch (e) { | |
console.error(e); | |
} | |
} | |
run(); | |
// Outputs: | |
// We do cleanup here | |
// Error: Thrown from thisThrows() | |
// at thisThrows (/repo/error_stacktrace_2.js:2:11) <-- Notice we now point to the origin of the actual error | |
// at myFunctionThatCatches (/repo/error_stacktrace_2.js:7:16) | |
// at run (/repo/error_stacktrace_2.js:18:15) | |
// at Object.<anonymous> (/repo/error_stacktrace_2.js:24:1) |
Same comment as here : https://gist.github.com/SegersIan/bbaaf0c034b943f4a3e2d9cd0524540e#gistcomment-3899714
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This misses an await in line 7, should be:
return await thisThrows();