O'Reilly logo

Just Enough C/C++ Programming by Guy W. Lecky-Thompson

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

Exception Handling

The final new part of C++ that you read about here is the ability to trap errors in the code so that you can perform processing to deal with the error. There are some errors, such as memory-allocation issues and incorrect usage of types, that can be trapped using an automated mechanism, and some that you need to cater to explicitly. After all, the latter ones are those that your program raises itself.

C++ has a collection of exceptions that it can throw, which deal with some specific cases. To throw something means to cause an exception. For example, trying to allocate more memory than is available causes a bad_alloc exception to be thrown.

So you need a mechanism to catch, or trap, these exceptions. You can do so by defining ...

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