The following code is generating the "Looser throw specifier error". Could you please help me to overcome this error?
class base
{
virtual void abc() throw (exp1);
}
void base::abc() throw (exp1)
{
......
}
class sub : public base
{
void abc() throw(exp1, exp2);
}
void sub::abc() throw (exp1, exp2)
{
.....
}
The problem comes about because the subclass must be usable wherever the base class can be used, and so must not throw any exception types other than those specified in the base class.
There are three solutions:
I would suggest removing them; they are widely regarded as a bad idea, partly because of issues like this. As Matthieu points out, the Standard Committee agrees, and exception specifiers are due to be deprecated in the next version of the Standard.
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