Error management is a fact of life in software development as it is often inevitable and generated by different causes that also include incorrect or incomplete understanding of the requirements or even lack of knowledge of some tools or elements used during development.
Let’s go on a small trip into the evolutions and different concepts related to error management, analyzing why it is difficult and why we are going in new directions after the moment of Exceptions in programming languages.
In languages such as C and C++, error handling was primarily based on return codes: specific values indicate the success or failure (sentinel value). This approach required the caller to check the return code, which could be ignored explicitly, and the control flow became convoluted due to the numerous checks scattered throughout the code base.
The notion of exception was introduced to address these challenges. The idea was to transfer the responsibility of error handling from the caller to a designated exception handler. When an exceptional situation arises, the runtime system throws an exception, which must be caught and handled by appropriate code. The introduction of already allocated exception handlers, like in Java, made it possible to catch/process Exceptions even if the system runs out of memory.