I'm looking to start making my JavaScript a bit more error proof, and I'm finding plenty of documentation on using try
, catch
, finally
, and throw
, but I'm not finding a ton of advice from experts on when and where to throw errors.
- Should every piece of code be wrapped in a try/catch?
- Is there more advice like this on at what point errors ought to be caught?
- Are there disadvantages to raising errors instead of having code fail silently in production?
- This has been touched on on SO as far as implementations, but have server-logging JS errors an effective strategy?
- Anything else I ought to know, regarding trapping errors in my application?
I'm also completely game for hearing of books that have great chapters or in-depth explanations of error-handling. Eloquent JavaScript touches on the matter, but isn't very prescriptive or opinionated about the issue.
Thanks for any advice you can give!