Reputation: 9982
In C++ concurrency in Action page 45 I have this code
#include <exception>
#include <memory>
struct empty_stack: std::exception
{
const char* what() const throw(); //<--- what does this mean?
}
Can anyone tell me what does this mean?
this empty_stack
exception is being thrown by another function if a stack is empty, such as
if(data.empty()) throw empty_stack();
but what does the line inside mean?
EDIT:
Someone posted (but was removed! wonder why) this link Thanks!
Upvotes: 1
Views: 742
Reputation: 122830
const char* what() const throw();
|-> return type
|-> name of the method
|-> parameter
|-> it is a const method
|-> exception specification
It is a const
method called what
that takes no parameters, returns a const char *
and is specified to not throw an exception.
Note the dynamic exception specifications are deprecated in C++11 and removed in C++17/20. For what it does I quote cppreference:
If the function throws an exception of the type not listed in its exception specification, the function
std::unexpected
is called. The default function callsstd::terminate
, but it may be replaced by a user-provided function (viastd::set_unexpected
) which may callstd::terminate
or throw an exception. If the exception thrown fromstd::unexpected
is accepted by the exception specification, stack unwinding continues as usual. If it isn't, butstd::bad_exception
is allowed by the exception specification,std::bad_exception
is thrown. Otherwise,std::terminate
is called.
Upvotes: 3