Programming with exceptions is difficult and inelegant. Learn how to handle errors better by representing them as values. In Smelly Exceptions, I laid out 3 practices to avoid when programming with exceptions. My goal there was to help you write mor...
Markdown supported · ⌘↵ to post
Maybe you have regular readers that know what language you always talk about, but for me, I had no idea what programming language you were talking about until I saw the tags at the bottom of your post. You might want to put "In TypeScript....." near the beginning of your articles so people who get here from random places on the internet know what you're talking about.
Capi Etheriel
Senior Instructor
That is hardly a fair example of error composition.
For starters,
Number.parseIntshould throw or be replaced with a throwingparseIntfunction (hiding the details).As for the
value > 3, we should not treat an error we raised ourselves! We should either have the caller deal with it or not throw at all: just useMath.minand be done with it.