From e9f25ddd0063f7ea65595178d04370d27344305c Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Wed, 9 Nov 2016 11:09:16 +0100 Subject: 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. --- src/protocol.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/protocol.cpp b/src/protocol.cpp index 54ad62b1a2..87d6e06848 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -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 &getAllNetMessageTypes() -- cgit v1.2.3