DEV Community

loading...

Discussion on: Nulling JavaScript

Collapse
kayis profile image
K Author

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.

Collapse
rpalo profile image
Ryan Palo

Ooh that makes sense. Cool, thanks!

Collapse
nomaed profile image
Nomæd

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.

Thread Thread
kayis profile image
K Author

I read that's the case for many languages.

Collapse
_prelevic profile image
Mark

isn't that why you now have promises and the .catch() there?

Thread Thread
kayis profile image
K Author

sure, but you're not always inside a promise

Collapse
joelnet profile image
JavaScript Joel

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.

Thread Thread
kayis profile image
K Author

Yeh, in statically typed languages you can at least easily filter what you wanna catch :/