Skip to content

Instantly share code, notes, and snippets.

@jmaicaaan
Last active March 31, 2021 13:10
Show Gist options
  • Save jmaicaaan/4ea9bbbf8f752dec86fbd5948084c0f3 to your computer and use it in GitHub Desktop.
Save jmaicaaan/4ea9bbbf8f752dec86fbd5948084c0f3 to your computer and use it in GitHub Desktop.
[Tutorial] Functional Try Catch
const getData = (id) => {
if (!id) {
throw new Error('No id found');
}
return [1, 2, 3, 4, 5].filter(i => i % id);
};
try {
const data = getData(2); // [1, 3, 5]
} catch (error) {
console.log('error', error);
}
// error
if (data.includes(1)) {
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment