In the following example, NameTooShort is thrown from
within a function that explicitly states that it will only throw NameTooLong
. This is a valid function, although at run time, if NameTooShort
is thrown, a call to unexpected() will be made.
#include <string.h> // needed for strlen class NameTooLong {}; class NameTooShort {}; void check(char* fname) throw (NameTooLong) { if ( strlen(fname)<4 ) throw NameTooShort(); }