Understanding error handling
Failures can show up in many parts of the app, either due to some lack of handling for the business logic or due to external circumstances such as the API being unreachable. The process of reacting to those errors gracefully without letting them crash the app is what’s called error handling.
Errors don’t always imply bad code or incorrect logic; these are just some of the causes of errors. Sometimes, the business logic of the app forces an error to be shown if the user is violating the rules. Other errors can be caused by external circumstances, such as the API being down. Writing good code can prevent programming errors. For example, if you are accessing a null object, that will throw a NullReferenceException
, but this exception is avoidable with better code management.
Let’s take an example of a feature that imports data into the system. The user can upload a file, and the logic of the feature forces this file to be either an...