Introduction
I spoke at OpenSlava 2020 a few weeks back, specifically around the levels of error handling you should apply to coding. However, I wanted a written article to refer to for those who don’t want to watch the video.
The below covers the 5 levels of error handling. I call them “levels” because the idea is to start with the lowest level, learn how it works, and then level up to the next. The ideal is that you utilize level 5 error handling, pattern matching, in all types of coding you do regardless of language. If you’re operating at that level, you’ll have more predictable code. There are other types of error handling, these are just the most common I’ve seen.
The error handling skill tree is as follows:
🏎 lvl 1: ignore ’em, dynamic languages have fast iteration
⚾️ lvl 2: try/catch/throw
🏭 lvl 3: Go/Lua style, function return values, pass back up
⛓ lvl 4: pipeline style, like JavaScript Promise
🌯 lvl 5: pattern match on returned types