Last active
March 31, 2021 13:10
-
-
Save jmaicaaan/4ea9bbbf8f752dec86fbd5948084c0f3 to your computer and use it in GitHub Desktop.
[Tutorial] Functional Try Catch
This file contains hidden or 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
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