Handling errors in CLI applications
Error handling may take two forms:
- An exception is raised, due to an unexpected event (such as an invalid input or an inaccessible dependency)
- The program is terminated, and we want to prevent it crashing by allowing it to gracefully shut down
In this section, we will cover both topics. Let’s start with exception handling.
Handling exceptions
There is nothing special about handling exceptions in a CLI application compared to other kinds of applications, as it follows the same guidelines and best practices. That’s why, in this section, you might find that you already know all the concepts that we are going to talk about, and that’s perfectly normal because you’d likely have implemented them in other applications, whether web, APIs, or desktop applications.
However, it is important to note that a robust error-handling strategy will have a significant impact on the quality, reliability, and resilience...