3 ms·
There doesn't need to be, if you expect the caller (or the top-level code) to handle errors. Also, how should the function handle errors? It's not immediately
by wereHamster 6y ago
There doesn't need to be, if you expect the caller (or the top-level code) to handle errors.
Also, how should the function handle errors? It's not immediately obvious. An empty array is not the correct thing to return (an empty array could be a valid return value). Returning undefined/null would be another option, but that hides the error from the caller (which might be interested in the exact error message, to be able to properly deal with it).
- jakear 6y agoSimple! try { ... } catch (e) { throw “an unknown error occurred” } ;)