This article is a "supplementary" article for the error handling series and for control flow for invalid conditions. It explains what the terms "error" and "non-errors" mean in those articles.
Let’s dive in.
Errors
Something that’s definitely an error is a bug. Some examples of bugs are:
- runtime exceptions
- calling a function with invalid arguments
- invalid state in your program. For example, something being
null
when it’s not supposed to be.
There are more things that are normally considered "errors". Some examples are:
- failing to send a network request, because the user lost internet connection
- failing to find a file, because the user deleted it a few milliseconds ago
These are things that your program can’t do anything about. They will fail sometimes. For example, your program might confirm that a user is connected to the internet. But, when it sends a network request, it may fail to send. Maybe the internet connection dropped halfway through the network request.
Non-errors
Most other things are not errors. They are considered "normal". For example, something in your program might be null
. If it’s supposed to be null
, it’s not an error. As another example, a user may provide invalid input. Again, that’s not an error. It’s normal and expected.
Credits
Error letters image – Photo by Ann H from Pexels