25 Nov 2019

  • November 25, 2019
  • Amitraj
Exception specification

-> Older code may contain dynamic exception specifications. They are now deprecated in C++, but still supported. A dynamic exception specification follows the declaration of a function, appending a throw specifier to it. For eg.


double myfunction (char tata) throw (int);


-> This declares a function called myfunction, which takes one argument of type char and returns a value of type double. If this function throws an exception of some type other than int, the function calls std::unexpected instead of looking for a handler or calling std::terminate.

-> If this throw specifier is left empty with no type, this means that std::unexpected is called for any exception. Functions with no throw specifier (regular functions) never call std::unexpected, but follow the normal path of looking for their exception handler.



1. int myfunction (int tata) throw(); // all exceptions call unexpected

2. int myfunction (int tata);      // normal exception handling 


Translate

Popular Posts