This site is stupid and teaches poor design.
If you choose intor char*, you only have to catch it with intor char*. You can qualify it with const.
If you throw it away std::runtime_error, you can catch it with std::runtime_error const &or with its base class std::exception const &.
So what is good?
, , , std::exception, ONE catch, std::exception const&, .
:
void f(A & a)
{
if ( !check_arg(a) )
{
throw std::invalid_argument("invalid argument");
}
else if ( !check_size(a) )
{
throw std::length_error("invalid length");
}
if(someCondition)
{
throw your_own_defined_exception("condition unsatisfied");
}
}
:
try
{
f(a);
}
catch(std::exception const &e)
{
}
, catch , f() . catch, -, - . : !
, .