DEV Community

Discussion on: Making Await More Functional in JavaScript

Collapse
 
brunobrant profile image
Bruno Brant

It seems that what you really want is to catch errors by type. All code examples revolve around this simple and good idea.

I must then make the horrible assertion that you must switch languages.

It's not only that js doesn't have catching by type, but that it goes against the design of the language itself.

Js is based on duck typing, an idea that you should never ask the type of an object and instead check whether it behaves the way you want.

I'm on your team - it sucks not being able to catch by type, and that's why I prefer statically typed languages - but as for js, embrace the paradigm.

On another note, the multiples try/catch blocks and unreadable code is correctly solved by splitting your method.

Collapse
 
jmitchell38488 profile image
Justin Mitchell • Edited

Not so much in es6 with object types. It's something that was present much earlier, but the concept that JS should just 'do' and not ask questions isn't relevant to its modern state. Sure, 15 years ago when most of the existing tools didn't exist, but not today.