Skip to Content
Navigating C++ and Object-Oriented Design
book

Navigating C++ and Object-Oriented Design

by Paul Anderson, Gail Anderson
October 1997
Intermediate to advanced
800 pages
20h 48m
English
Pearson
Content preview from Navigating C++ and Object-Oriented Design

13.1. Why Use Exceptions?

To see why exceptions are appealing, consider the following alternatives for error handling.

  1. Terminate the program.

  2. Return a value representing an error.

  3. Return a legal value, but set a global error flag.

  4. Call a user-supplied error function.

Each method has flaws. Terminating a program with exit(1) is unacceptable for embedded systems that must always run in a defined state. Returning a value that represents an error is not possible with many container classes (consider popping an empty integer Stack—what integer error code would be valid?) Returning a legal value after you set a global error code makes the tacit assumption that someone will check it. Not only are global variables error prone and unacceptable for concurrency, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Exploring C++20: The Programmer's Introduction to C++

Exploring C++20: The Programmer's Introduction to C++

Ray Lischner

Publisher Resources

ISBN: 0135327482Purchase book