Exceptions

In C++, an exception is an object that is passed from the area of code where a problem occurs to the part of the code that is going to handle the problem. When an exception occurs it is said to be “raised” or “thrown”. When an exception is handled, it is said to be “caught”.

The type of the exception determines which area of code will handle the problem; and the contents of the object thrown, if any, may be used to provide feedback to the user.

The basic idea behind exceptions is fairly straightforward:

  • The actual allocation of resources (for example, the allocation of memory or the locking of a file) is usually done at a very low level ...

Get Sams Teach Yourself C++ in 24 Hours, Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.