Skip to content

Instantly share code, notes, and snippets.

@oleoneto
Created August 19, 2021 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oleoneto/f56a197fb6a1b7e2dd9f05785a14c74c to your computer and use it in GitHub Desktop.
Save oleoneto/f56a197fb6a1b7e2dd9f05785a14c74c to your computer and use it in GitHub Desktop.
// 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