Merge pull request #10977 from ethereum/replace-throw-with-boost-macro

Replace raw throw with BOOST_THROW_EXCEPTION.
This commit is contained in:
chriseth
2021-02-22 16:18:13 +01:00
committed by GitHub
14 changed files with 70 additions and 67 deletions
+4 -4
View File
@@ -81,7 +81,7 @@ bytes BytesUtils::convertBoolean(string const& _literal)
else if (_literal == "false")
return bytes{false};
else
throw TestParserError("Boolean literal invalid.");
BOOST_THROW_EXCEPTION(TestParserError("Boolean literal invalid."));
}
bytes BytesUtils::convertNumber(string const& _literal)
@@ -92,7 +92,7 @@ bytes BytesUtils::convertNumber(string const& _literal)
}
catch (std::exception const&)
{
throw TestParserError("Number encoding invalid.");
BOOST_THROW_EXCEPTION(TestParserError("Number encoding invalid."));
}
}
@@ -104,7 +104,7 @@ bytes BytesUtils::convertHexNumber(string const& _literal)
}
catch (std::exception const&)
{
throw TestParserError("Hex number encoding invalid.");
BOOST_THROW_EXCEPTION(TestParserError("Hex number encoding invalid."));
}
}
@@ -116,7 +116,7 @@ bytes BytesUtils::convertString(string const& _literal)
}
catch (std::exception const&)
{
throw TestParserError("String encoding invalid.");
BOOST_THROW_EXCEPTION(TestParserError("String encoding invalid."));
}
}
+22 -19
View File
@@ -96,7 +96,7 @@ vector<solidity::frontend::test::FunctionCall> TestFileParser::parseFunctionCall
else if (m_scanner.currentLiteral() == "nonempty")
call.expectations.result.back().rawBytes = bytes(1, uint8_t(true));
else
throw TestParserError("Expected \"empty\" or \"nonempty\".");
BOOST_THROW_EXCEPTION(TestParserError("Expected \"empty\" or \"nonempty\"."));
call.kind = FunctionCall::Kind::Storage;
m_scanner.scanNextToken();
}
@@ -150,7 +150,9 @@ vector<solidity::frontend::test::FunctionCall> TestFileParser::parseFunctionCall
}
catch (TestParserError const& _e)
{
throw TestParserError("Line " + to_string(_lineOffset + m_lineNumber) + ": " + _e.what());
BOOST_THROW_EXCEPTION(
TestParserError("Line " + to_string(_lineOffset + m_lineNumber) + ": " + _e.what())
);
}
}
}
@@ -170,11 +172,12 @@ bool TestFileParser::accept(Token _token, bool const _expect)
bool TestFileParser::expect(Token _token, bool const _advance)
{
if (m_scanner.currentToken() != _token || m_scanner.currentToken() == Token::Invalid)
throw TestParserError(
BOOST_THROW_EXCEPTION(TestParserError(
"Unexpected " + formatToken(m_scanner.currentToken()) + ": \"" +
m_scanner.currentLiteral() + "\". " +
"Expected \"" + formatToken(_token) + "\"."
);
)
);
if (_advance)
m_scanner.scanNextToken();
return true;
@@ -206,10 +209,10 @@ pair<string, bool> TestFileParser::parseFunctionSignature()
parameters += parseIdentifierOrTuple();
}
if (accept(Token::Arrow, true))
throw TestParserError("Invalid signature detected: " + signature);
BOOST_THROW_EXCEPTION(TestParserError("Invalid signature detected: " + signature));
if (!hasName && !parameters.empty())
throw TestParserError("Signatures without a name cannot have parameters: " + signature);
BOOST_THROW_EXCEPTION(TestParserError("Signatures without a name cannot have parameters: " + signature));
else
signature += parameters;
@@ -226,7 +229,7 @@ FunctionValue TestFileParser::parseFunctionCallValue()
u256 value{ parseDecimalNumber() };
Token token = m_scanner.currentToken();
if (token != Token::Ether && token != Token::Wei)
throw TestParserError("Invalid value unit provided. Coins can be wei or ether.");
BOOST_THROW_EXCEPTION(TestParserError("Invalid value unit provided. Coins can be wei or ether."));
m_scanner.scanNextToken();
@@ -235,7 +238,7 @@ FunctionValue TestFileParser::parseFunctionCallValue()
}
catch (std::exception const&)
{
throw TestParserError("Ether value encoding invalid.");
BOOST_THROW_EXCEPTION(TestParserError("Ether value encoding invalid."));
}
}
@@ -245,7 +248,7 @@ FunctionCallArgs TestFileParser::parseFunctionCallArguments()
auto param = parseParameter();
if (param.abiType.type == ABIType::None)
throw TestParserError("No argument provided.");
BOOST_THROW_EXCEPTION(TestParserError("No argument provided."));
arguments.parameters.emplace_back(param);
while (accept(Token::Comma, true))
@@ -309,7 +312,7 @@ Parameter TestFileParser::parseParameter()
if (accept(Token::Boolean))
{
if (isSigned)
throw TestParserError("Invalid boolean literal.");
BOOST_THROW_EXCEPTION(TestParserError("Invalid boolean literal."));
parameter.abiType = ABIType{ABIType::Boolean, ABIType::AlignRight, 32};
string parsed = parseBoolean();
@@ -323,7 +326,7 @@ Parameter TestFileParser::parseParameter()
else if (accept(Token::HexNumber))
{
if (isSigned)
throw TestParserError("Invalid hex number literal.");
BOOST_THROW_EXCEPTION(TestParserError("Invalid hex number literal."));
parameter.abiType = ABIType{ABIType::Hex, ABIType::AlignRight, 32};
string parsed = parseHexNumber();
@@ -337,9 +340,9 @@ Parameter TestFileParser::parseParameter()
else if (accept(Token::Hex, true))
{
if (isSigned)
throw TestParserError("Invalid hex string literal.");
BOOST_THROW_EXCEPTION(TestParserError("Invalid hex string literal."));
if (parameter.alignment != Parameter::Alignment::None)
throw TestParserError("Hex string literals cannot be aligned or padded.");
BOOST_THROW_EXCEPTION(TestParserError("Hex string literals cannot be aligned or padded."));
string parsed = parseString();
parameter.rawString += "hex\"" + parsed + "\"";
@@ -351,9 +354,9 @@ Parameter TestFileParser::parseParameter()
else if (accept(Token::String))
{
if (isSigned)
throw TestParserError("Invalid string literal.");
BOOST_THROW_EXCEPTION(TestParserError("Invalid string literal."));
if (parameter.alignment != Parameter::Alignment::None)
throw TestParserError("String literals cannot be aligned or padded.");
BOOST_THROW_EXCEPTION(TestParserError("String literals cannot be aligned or padded."));
string parsed = parseString();
parameter.abiType = ABIType{ABIType::String, ABIType::AlignLeft, parsed.size()};
@@ -383,7 +386,7 @@ Parameter TestFileParser::parseParameter()
else if (accept(Token::Failure, true))
{
if (isSigned)
throw TestParserError("Invalid failure literal.");
BOOST_THROW_EXCEPTION(TestParserError("Invalid failure literal."));
parameter.abiType = ABIType{ABIType::Failure, ABIType::AlignRight, 0};
parameter.rawBytes = bytes{};
@@ -578,7 +581,7 @@ void TestFileParser::Scanner::scanNextToken()
m_currentLiteral = "";
}
else
throw TestParserError("Unexpected character: '" + string{current()} + "'");
BOOST_THROW_EXCEPTION(TestParserError("Unexpected character: '" + string{current()} + "'"));
break;
}
}
@@ -670,7 +673,7 @@ string TestFileParser::Scanner::scanString()
str += scanHexPart();
break;
default:
throw TestParserError("Invalid or escape sequence found in string literal.");
BOOST_THROW_EXCEPTION(TestParserError("Invalid or escape sequence found in string literal."));
}
}
else
@@ -693,7 +696,7 @@ char TestFileParser::Scanner::scanHexPart()
else if (tolower(current()) >= 'a' && tolower(current()) <= 'f')
value = tolower(current()) - 'a' + 10;
else
throw TestParserError("\\x used with no following hex digits.");
BOOST_THROW_EXCEPTION(TestParserError("\\x used with no following hex digits."));
advance();
if (current() == '"')