Search⌘ K
AI Features

Designing Interfaces with Error Handling

Explore error handling in C++ interface design by understanding programming and runtime errors, including recoverable and unrecoverable types. Learn to apply design by contract concepts such as preconditions, postconditions, and invariants to create robust APIs that clearly define error expectations and responsibilities.

We'll cover the following...

Error-proofing interface design

Error handling is an important and often overlooked part of the interface of functions and classes. Error handling is a heavily debated topic in C++, but often the discussions tend to focus on exceptions versus some other error mechanism. Although this is an interesting area, there are other aspects of error handling that are even more important to understand before focusing on the actual implementation of error handling.

Obviously, both exceptions and error codes have been used in numerous successful software projects, and it is not uncommon to stumble upon projects that combine the two.

A fundamental aspect of error handling, regardless of programming language, is to distinguish between programming errors (also known as bugs) and runtime errors. Runtime errors can be further divided into recoverable runtime errors and unrecoverable runtime errors. When an unrecoverable error occurs, the program typically terminates immediately, so ...