Why Use Exceptions?

Exceptions may seem somewhat more technical than if statements, but they are the preferred way to handle errors in C++. Whereas older libraries used to report errors with “error codes,” most modern libraries throw exceptions instead.

In addition, exception handling cleans up the code. While error handling is an important component of any real program, programmers generally want to read normal processing code and error-handling code separately, because that makes each of them easier to understand. Exceptions provide the best way to accomplish this.

Get SAMS Teach Yourself C++ in 10 Minutes SECOND EDITION now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.