Summary
This chapter has covered various techniques for error handling when working with POSIX APIs in C++. We discussed the use of errno
, a thread-local variable, and the strerror
function. We also explored how std::error_code
and std::error_condition
can wrap POSIX errors and how custom error categories enable us to compare errors generated by different sources and develop platform-independent error-handling code. Furthermore, we delved into exceptions in C++ and how to convert std::error_code
into an exception of the std::system_error
type.
We also examined best practices for working with exceptions, such as throwing them by value and catching them by reference, to avoid issues such as object slicing. Finally, we learned about the RAII technique in C++, which eliminates the need for a finally
construct in the language.
In the next chapter, we will explore the topic of concurrency with C++.