Avoid ugly exception in log on unknown inv type

It is unexpected behavior for `ToString` to raise an exception. It
is expected to do a best-effort attempt at formatting but never fail.

Catch the exception and simply print unknown inv types as hexadecimal.

Fixes #9110.
pull/308/head
Wladimir J. van der Laan 8 years ago
parent e9847303e7
commit e9f25ddd00

@ -181,7 +181,11 @@ std::string CInv::GetCommand() const
std::string CInv::ToString() const
{
return strprintf("%s %s", GetCommand(), hash.ToString());
try {
return strprintf("%s %s", GetCommand(), hash.ToString());
} catch(const std::out_of_range &) {
return strprintf("0x%08x %s", type, hash.ToString());
}
}
const std::vector<std::string> &getAllNetMessageTypes()

Loading…
Cancel
Save