Intermediate Business Programming with C++

It is possible to restrict what throws are permitted. For example see except8.cpp. In this example notice that the function: MYTEST() has the following header:

void MYTEST(int value) throw(int, char)

Notice to the right of the function name and the signature that a throw appears with a list of data types. This list of data types that follows the throw is called a throw list (or an exception specification). By theory the data types in the throw list are to be the only data types that should be thrown inside of this function. If any other data type is thrown, then the program should abort. Some compilers give a warning but they do not abort the program when a data type other than those listed is thrown as though it is supposed to. Other compilers do not seem to react to a throw list. Visual Studio .NET just gives a warning but ignores the throw list and the program executes normally. Try the above program in your compiler and see what it does with this program.

Категории