18.8 EXCEPTION SPECIFICATION
When we write a function it is possible to tell what exceptions can be raised by this function. In ideal case, programmers who want to use this function, we will be catching those in corresponding catch clause.
It is possible that this function will raise any other (type of) exception. We can term it as unexpected exception. The most important point to note is that when such an exception is thrown, it is not passed to catch clause. The program calls function unexpected() in that case. The default behaviour of this function is to call function terminate().
Let us study it with the help of a program.
Problem: Write a program to demonstrate that a function can specify which exceptions may be thrown during its exception. ...
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