Created
August 19, 2021 01:08
-
-
Save oleoneto/f56a197fb6a1b7e2dd9f05785a14c74c 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
// Just learned that a `return` inside try-catch blocks does not prevent the execution of code found in a `finally` block. | |
// Case and point, the example below: | |
const help = ({ command, logger }) => { | |
try { | |
console.log("Trying..."); | |
if (!command) { | |
console.log("Missing command. Halting...") | |
return false; | |
} | |
console.dir({ command, logger }); | |
} | |
catch (error) { | |
console.error("Error: ", error); | |
} | |
finally { | |
console.log("Program ended!"); | |
} | |
} | |
let command = { name: 'show', sys: 'terminal' } | |
help({ command }); | |
help({ command: undefined, logger: {} }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment