Skip to content

Commit

Permalink
Merge pull request #10977 from ethereum/replace-throw-with-boost-macro
Browse files Browse the repository at this point in the history
Replace raw throw with BOOST_THROW_EXCEPTION.
  • Loading branch information
chriseth authored Feb 22, 2021
2 parents 6fd5ea0 + c44bb7e commit e75e3fc
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 67 deletions.
10 changes: 5 additions & 5 deletions liblangutil/SemVerHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ SemVerVersion::SemVerVersion(string const& _versionString)
if (level < 2)
{
if (i == end || *i != '.')
throw SemVerError();
BOOST_THROW_EXCEPTION(SemVerError());
else
++i;
}
Expand All @@ -61,7 +61,7 @@ SemVerVersion::SemVerVersion(string const& _versionString)
build = string(buildStart, i);
}
if (i != end)
throw SemVerError();
BOOST_THROW_EXCEPTION(SemVerError());
}

bool SemVerMatchExpression::MatchComponent::matches(SemVerVersion const& _version) const
Expand Down Expand Up @@ -162,7 +162,7 @@ optional<SemVerMatchExpression> SemVerMatchExpressionParser::parse()
if (m_pos >= m_tokens.size())
break;
if (currentToken() != Token::Or)
throw SemVerError();
BOOST_THROW_EXCEPTION(SemVerError());
nextToken();
}
}
Expand Down Expand Up @@ -256,14 +256,14 @@ unsigned SemVerMatchExpressionParser::parseVersionPart()
{
c = currentChar();
if (v * 10 < v || v * 10 + static_cast<unsigned>(c - '0') < v * 10)
throw SemVerError();
BOOST_THROW_EXCEPTION(SemVerError());
v = v * 10 + static_cast<unsigned>(c - '0');
nextChar();
}
return v;
}
else
throw SemVerError();
BOOST_THROW_EXCEPTION(SemVerError());
}

char SemVerMatchExpressionParser::currentChar() const
Expand Down
2 changes: 1 addition & 1 deletion liblangutil/SemVerHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
namespace solidity::langutil
{

class SemVerError: util::Exception
class SemVerError: public util::Exception
{
};

Expand Down
10 changes: 5 additions & 5 deletions libsolidity/codegen/ir/IRGeneratorForStatements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ void IRGeneratorForStatements::generate(Block const& _block)
{
if (!boost::get_error_info<langutil::errinfo_sourceLocation>(_error))
_error << langutil::errinfo_sourceLocation(m_currentLocation);
throw _error;
BOOST_THROW_EXCEPTION(_error);
}
}

Expand Down Expand Up @@ -255,7 +255,7 @@ void IRGeneratorForStatements::initializeStateVar(VariableDeclaration const& _va
{
if (!boost::get_error_info<langutil::errinfo_sourceLocation>(_error))
_error << langutil::errinfo_sourceLocation(m_currentLocation);
throw _error;
BOOST_THROW_EXCEPTION(_error);
}
}

Expand All @@ -281,7 +281,7 @@ void IRGeneratorForStatements::initializeLocalVar(VariableDeclaration const& _va
{
if (!boost::get_error_info<langutil::errinfo_sourceLocation>(_error))
_error << langutil::errinfo_sourceLocation(m_currentLocation);
throw _error;
BOOST_THROW_EXCEPTION(_error);
}
}

Expand All @@ -300,7 +300,7 @@ IRVariable IRGeneratorForStatements::evaluateExpression(Expression const& _expre
{
if (!boost::get_error_info<langutil::errinfo_sourceLocation>(_error))
_error << langutil::errinfo_sourceLocation(m_currentLocation);
throw _error;
BOOST_THROW_EXCEPTION(_error);
}
}

Expand Down Expand Up @@ -333,7 +333,7 @@ string IRGeneratorForStatements::constantValueFunction(VariableDeclaration const
{
if (!boost::get_error_info<langutil::errinfo_sourceLocation>(_error))
_error << langutil::errinfo_sourceLocation(m_currentLocation);
throw _error;
BOOST_THROW_EXCEPTION(_error);
}
}

Expand Down
6 changes: 3 additions & 3 deletions test/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ bool CommonOptions::parse(int argc, char const* const* argv)
errorMessage << "Unrecognized option: ";
for (auto const& token: parsedOption.original_tokens)
errorMessage << token;
throw std::runtime_error(errorMessage.str());
BOOST_THROW_EXCEPTION(std::runtime_error(errorMessage.str()));
}

if (vmPaths.empty())
Expand Down Expand Up @@ -185,7 +185,7 @@ langutil::EVMVersion CommonOptions::evmVersion() const
{
auto version = langutil::EVMVersion::fromString(evmVersionString);
if (!version)
throw std::runtime_error("Invalid EVM version: " + evmVersionString);
BOOST_THROW_EXCEPTION(std::runtime_error("Invalid EVM version: " + evmVersionString));
return *version;
}
else
Expand All @@ -196,7 +196,7 @@ langutil::EVMVersion CommonOptions::evmVersion() const
CommonOptions const& CommonOptions::get()
{
if (!m_singleton)
throw std::runtime_error("Options not yet constructed!");
BOOST_THROW_EXCEPTION(std::runtime_error("Options not yet constructed!"));

return *m_singleton;
}
Expand Down
2 changes: 1 addition & 1 deletion test/CommonSyntaxTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace
int parseUnsignedInteger(string::iterator& _it, string::iterator _end)
{
if (_it == _end || !isdigit(*_it))
throw runtime_error("Invalid test expectation. Source location expected.");
BOOST_THROW_EXCEPTION(runtime_error("Invalid test expectation. Source location expected."));
int result = 0;
while (_it != _end && isdigit(*_it))
{
Expand Down
4 changes: 2 additions & 2 deletions test/EVMHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ bool EVMHost::checkVmPaths(vector<boost::filesystem::path> const& _vmPaths)
if (vm.has_capability(EVMC_CAPABILITY_EVM1))
{
if (evmVmFound)
throw runtime_error("Multiple evm1 evmc vms defined. Please only define one evm1 evmc vm.");
BOOST_THROW_EXCEPTION(runtime_error("Multiple evm1 evmc vms defined. Please only define one evm1 evmc vm."));
evmVmFound = true;
}

if (vm.has_capability(EVMC_CAPABILITY_EWASM))
{
if (ewasmVmFound)
throw runtime_error("Multiple ewasm evmc vms where defined. Please only define one ewasm evmc vm.");
BOOST_THROW_EXCEPTION(runtime_error("Multiple ewasm evmc vms where defined. Please only define one ewasm evmc vm."));
ewasmVmFound = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/TestCase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ bool TestCase::shouldRun()
void TestCase::expect(string::iterator& _it, string::iterator _end, string::value_type _c)
{
if (_it == _end || *_it != _c)
throw runtime_error(string("Invalid test expectation. Expected: \"") + _c + "\".");
BOOST_THROW_EXCEPTION(runtime_error(string("Invalid test expectation. Expected: \"") + _c + "\"."));
++_it;
}

Expand Down
10 changes: 5 additions & 5 deletions test/TestCaseReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ string TestCaseReader::stringSetting(string const& _name, string const& _default
void TestCaseReader::ensureAllSettingsRead() const
{
if (!m_unreadSettings.empty())
throw runtime_error(
BOOST_THROW_EXCEPTION(runtime_error(
"Unknown setting(s): " +
util::joinHumanReadable(m_unreadSettings | boost::adaptors::map_keys)
);
));
}

pair<SourceMap, size_t> TestCaseReader::parseSourcesAndSettingsWithLineNumber(istream& _stream)
Expand Down Expand Up @@ -134,7 +134,7 @@ pair<SourceMap, size_t> TestCaseReader::parseSourcesAndSettingsWithLineNumber(is
line.size() - sourceDelimiterEnd.size() - sourceDelimiterStart.size()
));
if (sources.count(currentSourceName))
throw runtime_error("Multiple definitions of test source \"" + currentSourceName + "\".");
BOOST_THROW_EXCEPTION(runtime_error("Multiple definitions of test source \"" + currentSourceName + "\"."));
}
else
currentSource += line + "\n";
Expand All @@ -143,15 +143,15 @@ pair<SourceMap, size_t> TestCaseReader::parseSourcesAndSettingsWithLineNumber(is
{
size_t colon = line.find(':');
if (colon == string::npos)
throw runtime_error(string("Expected \":\" inside setting."));
BOOST_THROW_EXCEPTION(runtime_error(string("Expected \":\" inside setting.")));
string key = line.substr(comment.size(), colon - comment.size());
string value = line.substr(colon + 1);
boost::algorithm::trim(key);
boost::algorithm::trim(value);
m_settings[key] = value;
}
else
throw runtime_error(string("Expected \"//\" or \"// ---\" to terminate settings and source."));
BOOST_THROW_EXCEPTION(runtime_error(string("Expected \"//\" or \"// ---\" to terminate settings and source.")));
}
// Register the last source as the main one
sources[currentSourceName] = currentSource;
Expand Down
8 changes: 4 additions & 4 deletions test/libsolidity/util/BytesUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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."));
}
}

Expand All @@ -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."));
}
}

Expand All @@ -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."));
}
}

Expand Down
41 changes: 22 additions & 19 deletions test/libsolidity/util/TestFileParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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())
);
}
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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();

Expand All @@ -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."));
}
}

Expand All @@ -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))
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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 + "\"";
Expand All @@ -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()};
Expand Down Expand Up @@ -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{};
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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
Expand All @@ -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() == '"')
Expand Down
Loading

0 comments on commit e75e3fc

Please sign in to comment.