17 The exceptional coder: Exception handling, logging, and QA
This chapter covers
- Understanding the concept of exception handling
- Learning how to throw and catch exceptions
- Exploring exception safety guarantee and best practices
- Unraveling the realm of logging
As you've learned so far, coding involves dealing with unexpected situations that can arise during program execution. Whether it's a file that's missing, a value that's out of range, or any number of unforeseen circumstances, C++'s exception handling mechanism provides an elegant solution to address these challenges.
We'll explore the fundamental concepts of exception handling, helping you understand how to gracefully manage errors and unexpected scenarios. We'll start by unraveling the basics, explaining what exceptions are, we'll guide you through the syntax and mechanics of throwing and catching exceptions. We'll provide real-world examples that illustrate the step-by-step process of raising exceptions when issues occur, and catching them to ensure your program continues executing smoothly. You'll gain insights into how to use various exception classes provided by the C++ Standard Library, each designed to cater to specific types of errors.
You will also learn about nested try-catch blocks, rethrowing exceptions, and utilizing the catch-all mechanism. You'll learn how to create custom exception classes tailored to your program's needs, enabling you to provide meaningful error messages and context to users.