Exception Specifications


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:

image from book

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

image from book

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.




Intermediate Business Programming with C++
Intermediate Business Programming with C++
ISBN: 738453099
EAN: N/A
Year: 2007
Pages: 142

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net