3 ms·
I don’t see how it changes anything. You’re still handling a second branch as if an error was thrown. It’s just called null. Practically, though, I like it be
by Waterluvian 2y ago
I don’t see how it changes anything. You’re still handling a second branch as if an error was thrown. It’s just called null.
Practically, though, I like it because JavaScript’s error handling sucks. I generally avoid using try/catch as a first class member of my software.
- aabhay 2y agoExactly! Handling null is still.. exception handling. You just check it with an if, not a try catch. But the semantics around try/catch are the main issue here and basically everywhere in JS. Error catching in JS is absolutely abysmal. Some examples: - nested try catch - not annotating that a function throws an error (or even being able to annotate in TS that it does) - async code throwing an error in a callback is uncatchable. E.G. file reader onread throwing an error. - not being able to narrow a catch to a specific error type.