Could anyone explain to me this definition of standard exception in C++:
virtual const char* what() const throw();
What does const throw() mean at the end?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
These are separate issues.
Regarding
constFrom the standard (if too long, only read the bold parts):
Summary: A member function qualified with
constis not allowed to change any member that is not declaredmutable. The reason formutableis that even if an object isconst, mechanism like caching can be done; it is good practice that the observable behavior of an object does not change by calling const member function.Regarding
throw()More specifically, it is a dynamic-exception-specification, and a
In other words, the types within
(and)are the exceptions that this function might throw. However, it is common practice to not use non-empty dynamic exception specifications for some good reasons.Using
throw(), i.e. an empty exception list, in pre-C++11 was accepted practice to annotate functions that never throw. However, as of C++11, the current standard, one should usenoexceptinstead.Also, as of C++11,
so use
noexceptinstead.