mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-21 11:35:53 +00:00
Convert throws and catch alls (RIPD-1046)
This commit is contained in:
committed by
Nik Bougalis
parent
0633ef1ba1
commit
880f354b90
@@ -45,7 +45,7 @@ std::int64_t
|
||||
getSNValue (STAmount const& amount)
|
||||
{
|
||||
if (!amount.native ())
|
||||
throw std::runtime_error ("amount is not native!");
|
||||
Throw<std::runtime_error> ("amount is not native!");
|
||||
|
||||
auto ret = static_cast<std::int64_t>(amount.mantissa ());
|
||||
|
||||
@@ -85,7 +85,7 @@ STAmount::STAmount(SerialIter& sit, SField const& name)
|
||||
|
||||
// negative
|
||||
if (value == 0)
|
||||
throw std::runtime_error ("negative zero is not canonical");
|
||||
Throw<std::runtime_error> ("negative zero is not canonical");
|
||||
|
||||
mValue = value;
|
||||
mOffset = 0;
|
||||
@@ -98,12 +98,12 @@ STAmount::STAmount(SerialIter& sit, SField const& name)
|
||||
issue.currency.copyFrom (sit.get160 ());
|
||||
|
||||
if (isXRP (issue.currency))
|
||||
throw std::runtime_error ("invalid native currency");
|
||||
Throw<std::runtime_error> ("invalid native currency");
|
||||
|
||||
issue.account.copyFrom (sit.get160 ());
|
||||
|
||||
if (isXRP (issue.account))
|
||||
throw std::runtime_error ("invalid native account");
|
||||
Throw<std::runtime_error> ("invalid native account");
|
||||
|
||||
// 10 bits for the offset, sign and "not native" flag
|
||||
int offset = static_cast<int>(value >> (64 - 10));
|
||||
@@ -120,7 +120,7 @@ STAmount::STAmount(SerialIter& sit, SField const& name)
|
||||
offset < cMinOffset ||
|
||||
offset > cMaxOffset)
|
||||
{
|
||||
throw std::runtime_error ("invalid currency value");
|
||||
Throw<std::runtime_error> ("invalid currency value");
|
||||
}
|
||||
|
||||
mIssue = issue;
|
||||
@@ -132,7 +132,7 @@ STAmount::STAmount(SerialIter& sit, SField const& name)
|
||||
}
|
||||
|
||||
if (offset != 512)
|
||||
throw std::runtime_error ("invalid currency value");
|
||||
Throw<std::runtime_error> ("invalid currency value");
|
||||
|
||||
mIssue = issue;
|
||||
mValue = 0;
|
||||
@@ -290,7 +290,7 @@ STAmount::construct (SerialIter& sit, SField const& name)
|
||||
XRPAmount STAmount::xrp () const
|
||||
{
|
||||
if (!mIsNative)
|
||||
throw std::logic_error ("Cannot return non-native STAmount as XRPAmount");
|
||||
Throw<std::logic_error> ("Cannot return non-native STAmount as XRPAmount");
|
||||
|
||||
auto drops = static_cast<std::int64_t> (mValue);
|
||||
|
||||
@@ -303,7 +303,7 @@ XRPAmount STAmount::xrp () const
|
||||
IOUAmount STAmount::iou () const
|
||||
{
|
||||
if (mIsNative)
|
||||
throw std::logic_error ("Cannot return native STAmount as IOUAmount");
|
||||
Throw<std::logic_error> ("Cannot return native STAmount as IOUAmount");
|
||||
|
||||
auto mantissa = static_cast<std::int64_t> (mValue);
|
||||
auto exponent = mOffset;
|
||||
@@ -335,7 +335,7 @@ STAmount& STAmount::operator-= (STAmount const& a)
|
||||
STAmount operator+ (STAmount const& v1, STAmount const& v2)
|
||||
{
|
||||
if (!areComparable (v1, v2))
|
||||
throw std::runtime_error ("Can't add amounts that are't comparable!");
|
||||
Throw<std::runtime_error> ("Can't add amounts that are't comparable!");
|
||||
|
||||
if (v2 == zero)
|
||||
return v1;
|
||||
@@ -430,7 +430,7 @@ getRate (STAmount const& offerOut, STAmount const& offerIn)
|
||||
std::uint64_t ret = r.exponent() + 100;
|
||||
return (ret << (64 - 8)) | r.mantissa();
|
||||
}
|
||||
catch (...)
|
||||
catch (std::exception const&)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -651,7 +651,7 @@ void STAmount::canonicalize ()
|
||||
}
|
||||
|
||||
if (mValue > cMaxNativeN)
|
||||
throw std::runtime_error ("Native currency amount out of range");
|
||||
Throw<std::runtime_error> ("Native currency amount out of range");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -674,7 +674,7 @@ void STAmount::canonicalize ()
|
||||
while (mValue > cMaxValue)
|
||||
{
|
||||
if (mOffset >= cMaxOffset)
|
||||
throw std::runtime_error ("value overflow");
|
||||
Throw<std::runtime_error> ("value overflow");
|
||||
|
||||
mValue /= 10;
|
||||
++mOffset;
|
||||
@@ -689,7 +689,7 @@ void STAmount::canonicalize ()
|
||||
}
|
||||
|
||||
if (mOffset > cMaxOffset)
|
||||
throw std::runtime_error ("value overflow");
|
||||
Throw<std::runtime_error> ("value overflow");
|
||||
|
||||
assert ((mValue == 0) || ((mValue >= cMinValue) && (mValue <= cMaxValue)));
|
||||
assert ((mValue == 0) || ((mOffset >= cMinOffset) && (mOffset <= cMaxOffset)));
|
||||
@@ -745,7 +745,7 @@ amountFromString (Issue const& issue, std::string const& amount)
|
||||
boost::smatch match;
|
||||
|
||||
if (!boost::regex_match (amount, match, reNumber))
|
||||
throw std::runtime_error ("Number '" + amount + "' is not valid");
|
||||
Throw<std::runtime_error> ("Number '" + amount + "' is not valid");
|
||||
|
||||
// Match fields:
|
||||
// 0 = whole input
|
||||
@@ -759,13 +759,13 @@ amountFromString (Issue const& issue, std::string const& amount)
|
||||
|
||||
// CHECKME: Why 32? Shouldn't this be 16?
|
||||
if ((match[2].length () + match[4].length ()) > 32)
|
||||
throw std::runtime_error ("Number '" + amount + "' is overlong");
|
||||
Throw<std::runtime_error> ("Number '" + amount + "' is overlong");
|
||||
|
||||
bool negative = (match[1].matched && (match[1] == "-"));
|
||||
|
||||
// Can't specify XRP using fractional representation
|
||||
if (isXRP(issue) && match[3].matched)
|
||||
throw std::runtime_error ("XRP must be specified in integral drops.");
|
||||
Throw<std::runtime_error> ("XRP must be specified in integral drops.");
|
||||
|
||||
std::uint64_t mantissa;
|
||||
int exponent;
|
||||
@@ -831,7 +831,7 @@ amountFromJson (SField const& name, Json::Value const& v)
|
||||
boost::split (elements, val, boost::is_any_of ("\t\n\r ,/"));
|
||||
|
||||
if (elements.size () > 3)
|
||||
throw std::runtime_error ("invalid amount string");
|
||||
Throw<std::runtime_error> ("invalid amount string");
|
||||
|
||||
value = elements[0];
|
||||
|
||||
@@ -853,21 +853,21 @@ amountFromJson (SField const& name, Json::Value const& v)
|
||||
if (native)
|
||||
{
|
||||
if (v.isObject ())
|
||||
throw std::runtime_error ("XRP may not be specified as an object");
|
||||
Throw<std::runtime_error> ("XRP may not be specified as an object");
|
||||
issue = xrpIssue ();
|
||||
}
|
||||
else
|
||||
{
|
||||
// non-XRP
|
||||
if (! to_currency (issue.currency, currency.asString ()))
|
||||
throw std::runtime_error ("invalid currency");
|
||||
Throw<std::runtime_error> ("invalid currency");
|
||||
|
||||
if (! issuer.isString ()
|
||||
|| !to_issuer (issue.account, issuer.asString ()))
|
||||
throw std::runtime_error ("invalid issuer");
|
||||
Throw<std::runtime_error> ("invalid issuer");
|
||||
|
||||
if (isXRP (issue.currency))
|
||||
throw std::runtime_error ("invalid issuer");
|
||||
Throw<std::runtime_error> ("invalid issuer");
|
||||
}
|
||||
|
||||
if (value.isInt ())
|
||||
@@ -896,7 +896,7 @@ amountFromJson (SField const& name, Json::Value const& v)
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error ("invalid amount type");
|
||||
Throw<std::runtime_error> ("invalid amount type");
|
||||
}
|
||||
|
||||
return { name, issue, mantissa, exponent, native, negative };
|
||||
@@ -937,7 +937,7 @@ bool
|
||||
operator< (STAmount const& lhs, STAmount const& rhs)
|
||||
{
|
||||
if (!areComparable (lhs, rhs))
|
||||
throw std::runtime_error ("Can't compare amounts that are't comparable!");
|
||||
Throw<std::runtime_error> ("Can't compare amounts that are't comparable!");
|
||||
|
||||
if (lhs.negative() != rhs.negative())
|
||||
return lhs.negative();
|
||||
@@ -981,7 +981,7 @@ STAmount
|
||||
divide (STAmount const& num, STAmount const& den, Issue const& issue)
|
||||
{
|
||||
if (den == zero)
|
||||
throw std::runtime_error ("division by zero");
|
||||
Throw<std::runtime_error> ("division by zero");
|
||||
|
||||
if (num == zero)
|
||||
return {issue};
|
||||
@@ -1017,7 +1017,7 @@ divide (STAmount const& num, STAmount const& den, Issue const& issue)
|
||||
(BN_mul_word64 (&v, tenTo17) != 1) ||
|
||||
(BN_div_word64 (&v, denVal) == ((std::uint64_t) - 1)))
|
||||
{
|
||||
throw std::runtime_error ("internal bn error");
|
||||
Throw<std::runtime_error> ("internal bn error");
|
||||
}
|
||||
|
||||
// 10^16 <= quotient <= 10^18
|
||||
@@ -1043,10 +1043,10 @@ multiply (STAmount const& v1, STAmount const& v2, Issue const& issue)
|
||||
? getSNValue (v2) : getSNValue (v1);
|
||||
|
||||
if (minV > 3000000000ull) // sqrt(cMaxNative)
|
||||
throw std::runtime_error ("Native value overflow");
|
||||
Throw<std::runtime_error> ("Native value overflow");
|
||||
|
||||
if (((maxV >> 32) * minV) > 2095475792ull) // cMaxNative / 2^32
|
||||
throw std::runtime_error ("Native value overflow");
|
||||
Throw<std::runtime_error> ("Native value overflow");
|
||||
|
||||
return STAmount (v1.getFName (), minV * maxV);
|
||||
}
|
||||
@@ -1082,7 +1082,7 @@ multiply (STAmount const& v1, STAmount const& v2, Issue const& issue)
|
||||
(BN_mul_word64 (&v, value2) != 1) ||
|
||||
(BN_div_word64 (&v, tenTo14) == ((std::uint64_t) - 1)))
|
||||
{
|
||||
throw std::runtime_error ("internal bn error");
|
||||
Throw<std::runtime_error> ("internal bn error");
|
||||
}
|
||||
|
||||
// 10^16 <= product <= 10^18
|
||||
@@ -1153,10 +1153,10 @@ mulRound (STAmount const& v1, STAmount const& v2,
|
||||
getSNValue (v2) : getSNValue (v1);
|
||||
|
||||
if (minV > 3000000000ull) // sqrt(cMaxNative)
|
||||
throw std::runtime_error ("Native value overflow");
|
||||
Throw<std::runtime_error> ("Native value overflow");
|
||||
|
||||
if (((maxV >> 32) * minV) > 2095475792ull) // cMaxNative / 2^32
|
||||
throw std::runtime_error ("Native value overflow");
|
||||
Throw<std::runtime_error> ("Native value overflow");
|
||||
|
||||
return STAmount (v1.getFName (), minV * maxV);
|
||||
}
|
||||
@@ -1188,13 +1188,13 @@ mulRound (STAmount const& v1, STAmount const& v2,
|
||||
CBigNum v;
|
||||
|
||||
if ((BN_add_word64 (&v, value1) != 1) || (BN_mul_word64 (&v, value2) != 1))
|
||||
throw std::runtime_error ("internal bn error");
|
||||
Throw<std::runtime_error> ("internal bn error");
|
||||
|
||||
if (resultNegative != roundUp) // rounding down is automatic when we divide
|
||||
BN_add_word64 (&v, tenTo14m1);
|
||||
|
||||
if (BN_div_word64 (&v, tenTo14) == ((std::uint64_t) - 1))
|
||||
throw std::runtime_error ("internal bn error");
|
||||
Throw<std::runtime_error> ("internal bn error");
|
||||
|
||||
// 10^16 <= product <= 10^18
|
||||
assert (BN_num_bytes (&v) <= 64);
|
||||
@@ -1211,7 +1211,7 @@ divRound (STAmount const& num, STAmount const& den,
|
||||
Issue const& issue, bool roundUp)
|
||||
{
|
||||
if (den == zero)
|
||||
throw std::runtime_error ("division by zero");
|
||||
Throw<std::runtime_error> ("division by zero");
|
||||
|
||||
if (num == zero)
|
||||
return {issue};
|
||||
@@ -1239,13 +1239,13 @@ divRound (STAmount const& num, STAmount const& den,
|
||||
CBigNum v;
|
||||
|
||||
if ((BN_add_word64 (&v, numVal) != 1) || (BN_mul_word64 (&v, tenTo17) != 1))
|
||||
throw std::runtime_error ("internal bn error");
|
||||
Throw<std::runtime_error> ("internal bn error");
|
||||
|
||||
if (resultNegative != roundUp) // Rounding down is automatic when we divide
|
||||
BN_add_word64 (&v, denVal - 1);
|
||||
|
||||
if (BN_div_word64 (&v, denVal) == ((std::uint64_t) - 1))
|
||||
throw std::runtime_error ("internal bn error");
|
||||
Throw<std::runtime_error> ("internal bn error");
|
||||
|
||||
// 10^16 <= quotient <= 10^18
|
||||
assert (BN_num_bytes (&v) <= 64);
|
||||
@@ -1271,7 +1271,7 @@ mulDiv(std::uint64_t value, std::uint64_t mul, std::uint64_t div)
|
||||
{
|
||||
value /= div;
|
||||
if (value > max / mul)
|
||||
throw std::overflow_error("mulDiv");
|
||||
Throw<std::overflow_error> ("mulDiv");
|
||||
return value * mul;
|
||||
}
|
||||
return value * mul / div;
|
||||
|
||||
Reference in New Issue
Block a user