O'Reilly logo

Essential C++ by Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

7.3. Trying for an Exception

Catch clauses are associated with try blocks. A try block begins with the try keyword followed by a sequence of program statements enclosed in braces. The catch clauses are placed at the end of the try block, and they represent the exceptions that are handled if an exception is thrown during execution of the statements within the try block.

For example, the following function looks for elem within a range of elements marked by first, last. The iteration over the range can potentially result in an iterator_overflow exception being thrown, so we place that code within a try block followed by a catch clause that contains an iterator_overflow exception declaration:

 bool has_elem( Triangular_iterator first, Triangular_iterator ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required