I have a question about the catch block for try/catch combinations. I am using the try statement without caring what the specific error is, just that an error was thrown. Hence, I used the catch (...)
construct which will capture anything. To show what I mean, here is the code in its entirety:
try
{
tmp_rgb[0] = static_cast<double> (stoi (str.substr (1,1), nullptr, 16))
/ 15.0;
tmp_rgb[1] = static_cast<double> (stoi (str.substr (2,1), nullptr, 16))
/ 15.0;
tmp_rgb[2] = static_cast<double> (stoi (str.substr (3,1), nullptr, 16))
/ 15.0;
}
catch (...)
{
retval = false;
}
The function stoi
is part of the std
library so it will throw a variable of type std::exception
. Should I explicitly look for that? To my mind, it seems overly verbose to include that type information when I have no plans to use it. I guess I think of it similarly to using the auto
keyword when I don’t particularly care to know what the type is.