Writing code for error handling
To see how important handling errors is, we have to think of our system as a whole, including inputs and output. Our code by itself might never experience an error; however, when integrated with other systems, it might cause unpredictable outputs, or might just crash and stop working.
Therefore, handling errors is important to cope with the unpredictability of inputs and protect your code to avoid wrong outputs or crashes. But how do we do that?
First, we need to identify our inputs, and then we create a series of different combinations of values that are sent to our inputs. The behavior of these input combinations are then evaluated by running our code. For a function, we do that by adding unit tests, as we discussed in Chapter 5. For the system, we add integration tests and end-to-end testing. Additional techniques were also discussed in Chapter 5.
But what is the correct way to write code for handling errors? It will depend on the language...