4 ms·
Another place throws are inconvenient is chaining/streams. Pseudocode: var goodStuff = listOfStuff.map(x => transform(x)) .filter(t => typeof(t.re
by libria 6y ago
Another place throws are inconvenient is chaining/streams.
Pseudocode:
var goodStuff = listOfStuff.map(x => transform(x))
.filter(t => typeof(t.result) != Error)
.map(y => handleGoodData(y))
If `transform()` threw exceptions, this whole thing aborts. But if it can return an `Error` type, we can continue processing the good ones and log the bad ones (here I ignore them for simplicity).