I have looked through underscore.js and backbone.js, both two very popular libraries and noticed that they don't use error handling (try, catch, exception).
What is the reason for this decision?
Actually when you write quality javascript code you don't really need try/catch. Exceptional logic is handled through if conditions and error handlers instead of catching exceptions at runtime.
A quick look at these libraries does reveal several uses of throw
and catch
, so they do use exceptions, albeit sparingly.
Exceptions are useful where extra parameters could make functions cumbersome and unreadable and/or 'normal' preconditions for running the code have been badly broken beyond a predictable error case.
It seems a bit confusing to use the term 'error handling' as if you avoid exceptions but pass back an error value from a function this is still error handling.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With