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 ...
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.
Read now
Unlock full access