Catch std::ios_base::failure exceptions, which mean EOF when reading JSON from a std::stringstream

This commit is contained in:
Eric Frias 2014-06-04 16:55:05 -04:00
parent 942545df5e
commit ff04a5a8fb

View file

@ -132,6 +132,11 @@ namespace fc
{
return token.str();
}
catch (const std::ios_base::failure&)
{
return token.str();
}
FC_RETHROW_EXCEPTIONS( warn, "while parsing token '${token}'",
("token", token.str() ) );
}
@ -179,6 +184,10 @@ namespace fc
catch( const fc::eof_exception& e )
{
FC_THROW_EXCEPTION( parse_error_exception, "Unexpected EOF: ${e}", ("e", e.to_detail_string() ) );
}
catch( const std::ios_base::failure& e )
{
FC_THROW_EXCEPTION( parse_error_exception, "Unexpected EOF: ${e}", ("e", e.what() ) );
} FC_RETHROW_EXCEPTIONS( warn, "Error parsing object" );
}
@ -261,6 +270,9 @@ namespace fc
catch (fc::eof_exception&)
{
}
catch (const std::ios_base::failure&)
{
}
fc::string str = ss.str();
if (str == "-." || str == ".") // check the obviously wrong things we could have encountered
FC_THROW_EXCEPTION(parse_error_exception, "Can't parse token \"${token}\" as a JSON numeric constant", ("token", str));
@ -306,6 +318,10 @@ namespace fc
{
received_eof = true;
}
catch (const std::ios_base::failure&)
{
received_eof = true;
}
// we can get here either by processing a delimiter as in "null,"
// an EOF like "null<EOF>", or an invalid token like "nullZ"