Exceptions with Class Objects
In the examples above, the throw statements not only send control to a catch block, but also pass along a value of the specific type. This value can be accessed in the catch block. This technique is an important means of establishing communications between the place of error discovery and the place of error recovery.
Sending a value of a specific type is both a privilege (communication is established) and a limitation because a function cannot throw the values of the same type so that they would be processed by different catch blocks. For example, if a function throws two different character strings from two different places, these two strings must be processed by the same catch block. If the error recovery is limited ...
Get Core C++ A Software Engineering Approach 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.