Ryan is an engineer in the Sacramento Area with a focus in Python, Ruby, and Rust. Bash/Python Exercism mentor. Coding, physics, calculus, music, woodworking. Looking for work!
Cofounded Host Collective (DiscountASP.net). Cofounded Player Axis (Social Gaming). Computer Scientist and Technology Evangelist with 20+ years of experience with JavaScript!
Try-Catch aren't popular in JS because engines can't optimize the code well, or something of this sort that I read somewhere a while ago. I use Try-Catch with promises quite often.
You're totally right. Somehow JS devs aren't too fond of try-catch, guess it's like you said: too explicit?
Maybe it has also to do with the async nature of JS code, you simply couldn't catch them callbacks, so many people didn't use it too often.
Ooh that makes sense. Cool, thanks!
I have been told "Avoid using exceptions for control flow". If you know something might throw an exception and you can check for it, do that instead.
A try block is also greedy and you may end up swallowing more than what you were hoping for, which can be a PITA for chasing down odd errors.
Yeh, in statically typed languages you can at least easily filter what you wanna catch :/
isn't that why you now have promises and the .catch() there?
sure, but you're not always inside a promise
Try-Catch aren't popular in JS because engines can't optimize the code well, or something of this sort that I read somewhere a while ago. I use Try-Catch with promises quite often.
I read that's the case for many languages.