In /std:c++17 mode, throw() is an alias for noexcept(true) . In /std:c++17 mode and later, when an exception is thrown from a function declared with any of these specifications, std::terminate is invoked as required by the C++17 standard.
The object, called an exception object, contains information about the error, including its type and the state of the program when the error occurred. Creating an exception object and handing it to the runtime system is called throwing an exception.
A throw() specification on a function declaration indicates which specific exception(s) the function is allowed to throw to the caller. It is a kind of contract so the caller knows what to expect. If no throw() is specified, the function is allowed to throw any exception.
The throw statement throws a user-defined exception. Execution of the current function will stop (the statements after throw won't be executed), and control will be passed to the first catch block in the call stack. If no catch block exists among caller functions, the program will terminate.
std::exception class is defined as follows
exception() throw() { }
virtual ~exception() throw();
virtual const char* what() const throw();
what does the throw() syntax mean in a declaration? Can throw() take parameters? What does no parameters mean?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With