diff --git a/Builds/VisualStudio2015/RippleD.vcxproj b/Builds/VisualStudio2015/RippleD.vcxproj index 5dac8331b..02000b7fe 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj +++ b/Builds/VisualStudio2015/RippleD.vcxproj @@ -1980,6 +1980,10 @@ True True + + True + True + True True diff --git a/Builds/VisualStudio2015/RippleD.vcxproj.filters b/Builds/VisualStudio2015/RippleD.vcxproj.filters index 4d725047a..cc6d5a1f7 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2015/RippleD.vcxproj.filters @@ -2718,6 +2718,9 @@ ripple\basics\tests + + ripple\basics\tests + ripple\basics\tests diff --git a/src/ripple/app/ledger/ConsensusTransSetSF.cpp b/src/ripple/app/ledger/ConsensusTransSetSF.cpp index 374bc43ac..6f862934a 100644 --- a/src/ripple/app/ledger/ConsensusTransSetSF.cpp +++ b/src/ripple/app/ledger/ConsensusTransSetSF.cpp @@ -67,7 +67,7 @@ void ConsensusTransSetSF::gotNode ( pap->getOPs().submitTransaction(stx); }); } - catch (...) + catch (std::exception const&) { JLOG (j_.warning) << "Fetched invalid transaction in proposed set"; diff --git a/src/ripple/app/ledger/Ledger.cpp b/src/ripple/app/ledger/Ledger.cpp index 74c623b89..d210ef64d 100644 --- a/src/ripple/app/ledger/Ledger.cpp +++ b/src/ripple/app/ledger/Ledger.cpp @@ -243,7 +243,7 @@ Ledger::Ledger (uint256 const& parentHash, if (! setup(config)) loaded = false; - + if (! loaded) { updateHash (); @@ -456,7 +456,7 @@ deserializeTxPlusMeta (SHAMapItem const& item) void Ledger::setAcquiring (void) { if (!txMap_ || !stateMap_) - throw std::runtime_error ("invalid map"); + Throw ("invalid map"); txMap_->setSynching (); stateMap_->setSynching (); @@ -721,12 +721,11 @@ Ledger::setup (Config const& config) { ret = false; } - catch (...) + catch (std::exception const&) { - throw; + Throw(); } - try { rules_ = Rules(*this); @@ -735,9 +734,9 @@ Ledger::setup (Config const& config) { ret = false; } - catch (...) + catch (std::exception const&) { - throw; + Throw(); } return ret; @@ -783,7 +782,7 @@ void Ledger::visitStateItems (std::function callback) const catch (SHAMapMissingNode&) { stateMap_->family().missing_node (info_.hash); - throw; + Throw(); } } @@ -999,7 +998,7 @@ static bool saveValidatedLedger ( app.getAcceptedLedgerCache().canonicalize(ledger->info().hash, aLedger); } } - catch (...) + catch (std::exception const&) { JLOG (j.warning) << "An accepted ledger was missing nodes"; app.getLedgerMaster().failedSave(seq, ledger->info().hash); diff --git a/src/ripple/app/ledger/OpenLedger.h b/src/ripple/app/ledger/OpenLedger.h index a77856dd8..fd8f90c8c 100644 --- a/src/ripple/app/ledger/OpenLedger.h +++ b/src/ripple/app/ledger/OpenLedger.h @@ -224,7 +224,7 @@ OpenLedger::apply (Application& app, OpenView& view, if (result == Result::retry) retries.insert(tx); } - catch(...) + catch(std::exception const&) { JLOG(j.error) << "Caught exception"; diff --git a/src/ripple/app/ledger/OrderBookDB.cpp b/src/ripple/app/ledger/OrderBookDB.cpp index 103c2de2c..a54b7be24 100644 --- a/src/ripple/app/ledger/OrderBookDB.cpp +++ b/src/ripple/app/ledger/OrderBookDB.cpp @@ -282,7 +282,7 @@ void OrderBookDB::processTxn ( } } } - catch (...) + catch (std::exception const&) { JLOG (j_.info) << "Fields not found in OrderBookDB::processTxn"; diff --git a/src/ripple/app/ledger/impl/InboundLedgers.cpp b/src/ripple/app/ledger/impl/InboundLedgers.cpp index 258e9b3cc..4c6e64e63 100644 --- a/src/ripple/app/ledger/impl/InboundLedgers.cpp +++ b/src/ripple/app/ledger/impl/InboundLedgers.cpp @@ -271,7 +271,7 @@ public: newNode->getNodeHash().as_uint256(), blob); } } - catch (...) + catch (std::exception const&) { } } diff --git a/src/ripple/app/ledger/impl/LedgerConsensusImp.cpp b/src/ripple/app/ledger/impl/LedgerConsensusImp.cpp index 16d048772..ff06a209a 100644 --- a/src/ripple/app/ledger/impl/LedgerConsensusImp.cpp +++ b/src/ripple/app/ledger/impl/LedgerConsensusImp.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -531,7 +532,7 @@ void LedgerConsensusImp::mapComplete ( leaveConsensus(); JLOG (j_.error) << "Missing node processing complete map " << mn; - throw; + Throw(); } } @@ -731,7 +732,7 @@ void LedgerConsensusImp::timerEntry () leaveConsensus (); JLOG (j_.error) << "Missing node during consensus process " << mn; - throw; + Throw(); } } @@ -1167,7 +1168,7 @@ void LedgerConsensusImp::accept (std::shared_ptr set) anyDisputes = true; } - catch (...) + catch (std::exception const&) { JLOG (j_.debug) << "Failed to apply transaction we voted NO on"; @@ -1857,7 +1858,7 @@ applyTransaction (Application& app, OpenView& view, << "Transaction retry: " << transHuman (result.first); return LedgerConsensusImp::resultRetry; } - catch (...) + catch (std::exception const&) { JLOG (j.warning) << "Throws"; return LedgerConsensusImp::resultFail; @@ -1889,7 +1890,7 @@ void applyTransactions ( { txn = std::make_shared(SerialIter{item.slice()}); } - catch (...) + catch (std::exception const&) { JLOG (j.warning) << " Throws"; } @@ -1933,7 +1934,7 @@ void applyTransactions ( ++it; } } - catch (...) + catch (std::exception const&) { JLOG (j.warning) << "Transaction throws"; diff --git a/src/ripple/app/ledger/impl/LedgerMaster.cpp b/src/ripple/app/ledger/impl/LedgerMaster.cpp index 68d83c805..1e30369ee 100644 --- a/src/ripple/app/ledger/impl/LedgerMaster.cpp +++ b/src/ripple/app/ledger/impl/LedgerMaster.cpp @@ -629,7 +629,7 @@ public: { hash = hashOfSeq(*ledger, lSeq, m_journal); } - catch (...) + catch (std::exception const&) { JLOG (m_journal.warning) << "fixMismatch encounters partial ledger"; @@ -984,7 +984,7 @@ public: { doAdvance(); } - catch (...) + catch (std::exception const&) { JLOG (m_journal.fatal) << "doAdvance throws an exception"; } @@ -1106,7 +1106,7 @@ public: } } - catch (...) + catch (std::exception const&) { JLOG (m_journal.error) << "findNewLedgersToPublish catches an exception"; @@ -1501,7 +1501,7 @@ public: if (hash) return mLedgerHistory.getLedgerByHash (*hash); } - catch (...) + catch (std::exception const&) { // Missing nodes are already handled } @@ -1734,7 +1734,7 @@ void LedgerMasterImp::doAdvance () InboundLedger::fcHISTORY); } } - catch (...) + catch (std::exception const&) { JLOG (m_journal.warning) << "Threw while prefetching"; @@ -1962,7 +1962,7 @@ void LedgerMasterImp::makeFetchPack ( auto msg = std::make_shared (reply, protocol::mtGET_OBJECTS); peer->send (msg); } - catch (...) + catch (std::exception const&) { m_journal.warning << "Exception building fetch pach"; } diff --git a/src/ripple/app/ledger/impl/LedgerToJson.cpp b/src/ripple/app/ledger/impl/LedgerToJson.cpp index d7917204d..c55ec83ba 100644 --- a/src/ripple/app/ledger/impl/LedgerToJson.cpp +++ b/src/ripple/app/ledger/impl/LedgerToJson.cpp @@ -117,7 +117,7 @@ void fillJsonTx (Object& json, LedgerFill const& fill) } } } - catch (...) + catch (std::exception const&) { // Nothing the user can do about this. } diff --git a/src/ripple/app/ledger/impl/OpenLedger.cpp b/src/ripple/app/ledger/impl/OpenLedger.cpp index 9713853de..a73d8ec3b 100644 --- a/src/ripple/app/ledger/impl/OpenLedger.cpp +++ b/src/ripple/app/ledger/impl/OpenLedger.cpp @@ -184,7 +184,7 @@ debugTostr (SHAMap const& set) STTx const>(sit); ss << debugTxstr(tx) << ", "; } - catch(...) + catch(std::exception const&) { ss << "THRO, "; } diff --git a/src/ripple/app/ledger/impl/TransactionAcquire.cpp b/src/ripple/app/ledger/impl/TransactionAcquire.cpp index fe2dfbabc..839a1cb87 100644 --- a/src/ripple/app/ledger/impl/TransactionAcquire.cpp +++ b/src/ripple/app/ledger/impl/TransactionAcquire.cpp @@ -226,7 +226,7 @@ SHAMapAddNode TransactionAcquire::takeNodes (const std::list& node progress (); return SHAMapAddNode::useful (); } - catch (...) + catch (std::exception const&) { JLOG (j_.error) << "Peer sends us junky transaction node data"; return SHAMapAddNode::invalid (); diff --git a/src/ripple/app/main/Application.cpp b/src/ripple/app/main/Application.cpp index eb2803bc6..a37a2ec01 100644 --- a/src/ripple/app/main/Application.cpp +++ b/src/ripple/app/main/Application.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -1047,7 +1048,7 @@ void ApplicationImp::setup() { m_journal.fatal << "Could not create Websocket for [" << port.name << "]"; - throw std::exception(); + Throw (); } websocketServers_.emplace_back (std::move (server)); } @@ -1526,7 +1527,7 @@ static bool schemaHas ( if (static_cast (schema.size ()) <= line) { JLOG (j.fatal) << "Schema for " << dbName << " has too few lines"; - throw std::runtime_error ("bad schema"); + Throw ("bad schema"); } return schema[line].find (content) != std::string::npos; diff --git a/src/ripple/app/main/LocalCredentials.cpp b/src/ripple/app/main/LocalCredentials.cpp index 84c7a4902..c17f8100f 100644 --- a/src/ripple/app/main/LocalCredentials.cpp +++ b/src/ripple/app/main/LocalCredentials.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -46,7 +47,7 @@ void LocalCredentials::start () nodeIdentityCreate (); if (!nodeIdentityLoad ()) - throw std::runtime_error ("unable to retrieve new node identity."); + Throw ("unable to retrieve new node identity."); } if (!app_.config().QUIET) diff --git a/src/ripple/app/main/Main.cpp b/src/ripple/app/main/Main.cpp index e42614a67..8eb7a3c42 100644 --- a/src/ripple/app/main/Main.cpp +++ b/src/ripple/app/main/Main.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -298,7 +299,7 @@ int run (int argc, char** argv) vm); po::notify (vm); // Invoke option notify functions. } - catch (...) + catch (std::exception const&) { std::cerr << "rippled: Incorrect command line syntax." << std::endl; std::cerr << "Use '--help' for a list of options." << std::endl; @@ -421,7 +422,7 @@ int run (int argc, char** argv) boost::asio::ip::address_v4::from_string( vm["rpc_ip"].as())); } - catch(...) + catch(std::exception const&) { std::cerr << "Invalid rpc_ip = " << vm["rpc_ip"].as() << std::endl; @@ -439,9 +440,9 @@ int run (int argc, char** argv) vm["rpc_port"].as()); if (*config->rpc_port == 0) - throw std::domain_error (""); + Throw (""); } - catch(...) + catch(std::exception const&) { std::cerr << "Invalid rpc_port = " << vm["rpc_port"].as() << std::endl; @@ -457,9 +458,9 @@ int run (int argc, char** argv) config->LOCK_QUORUM = true; if (config->VALIDATION_QUORUM < 0) - throw std::domain_error (""); + Throw (""); } - catch(...) + catch(std::exception const&) { std::cerr << "Invalid quorum = " << vm["quorum"].as () << std::endl; diff --git a/src/ripple/app/misc/AmendmentTableImpl.cpp b/src/ripple/app/misc/AmendmentTableImpl.cpp index ae2ee4c72..5097bf1e0 100644 --- a/src/ripple/app/misc/AmendmentTableImpl.cpp +++ b/src/ripple/app/misc/AmendmentTableImpl.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -135,7 +136,7 @@ AmendmentTableImpl::addInitial (Section const& section) "preEnabledAmendments contains an invalid hash (expected " "a hex number). Value was: %1%") % a.hexString ()).str (); - throw std::runtime_error (errorMsg); + Throw (errorMsg); } } @@ -157,7 +158,7 @@ AmendmentTableImpl::addInitial (Section const& section) "items. Found %3%. Line was: %4%") % SECTION_AMENDMENTS % numExpectedToks % tokens.size () % line).str (); - throw std::runtime_error (errorMsg); + Throw (errorMsg); } toAdd.emplace_back (std::move (tokens[0]), std::move (tokens[1])); @@ -170,7 +171,7 @@ AmendmentTableImpl::addInitial (Section const& section) "%3%") % toAdd.back ().hexString () % SECTION_AMENDMENTS % line).str (); - throw std::runtime_error (errorMsg); + Throw (errorMsg); } } } @@ -233,7 +234,7 @@ AmendmentTableImpl::addKnown (AmendmentName const& name) "addKnown was given an invalid hash (expected a hex number). " "Value was: %1%") % name.hexString ()).str (); - throw std::runtime_error (errorMsg); + Throw (errorMsg); } std::lock_guard sl (mLock); diff --git a/src/ripple/app/misc/NetworkOPs.cpp b/src/ripple/app/misc/NetworkOPs.cpp index eb7673c94..eb999dbea 100644 --- a/src/ripple/app/misc/NetworkOPs.cpp +++ b/src/ripple/app/misc/NetworkOPs.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -767,7 +768,7 @@ void NetworkOPsImp::submitTransaction (std::shared_ptr const& iTrans return; } } - catch (...) + catch (std::exception const&) { JLOG(m_journal.warning) << "Exception checking transaction" << txid; @@ -1259,7 +1260,7 @@ bool NetworkOPsImp::checkLastClosedLedger ( ++vc.nodesUsing; } - catch (...) + catch (std::exception const&) { // Peer is likely not connected anymore } @@ -2539,7 +2540,7 @@ std::uint32_t NetworkOPsImp::acceptLedger () assert (m_standalone); if (!m_standalone) - throw std::runtime_error ("Operation only possible in STANDALONE mode."); + Throw ("Operation only possible in STANDALONE mode."); // FIXME Could we improve on this and remove the need for a specialized // API in LedgerConsensus? diff --git a/src/ripple/app/misc/SHAMapStoreImp.cpp b/src/ripple/app/misc/SHAMapStoreImp.cpp index c99bdc484..50b26fd54 100644 --- a/src/ripple/app/misc/SHAMapStoreImp.cpp +++ b/src/ripple/app/misc/SHAMapStoreImp.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -62,7 +63,7 @@ void SHAMapStoreImp::SavedStateDB::init (BasicConfig const& config, "SELECT COUNT(Key) FROM DbState WHERE Key = 1;" , soci::into (countO); if (!countO) - throw std::runtime_error("Failed to fetch Key Count from DbState."); + Throw ("Failed to fetch Key Count from DbState."); count = *countO; } @@ -79,7 +80,7 @@ void SHAMapStoreImp::SavedStateDB::init (BasicConfig const& config, "SELECT COUNT(Key) FROM CanDelete WHERE Key = 1;" , soci::into (countO); if (!countO) - throw std::runtime_error("Failed to fetch Key Count from CanDelete."); + Throw ("Failed to fetch Key Count from CanDelete."); count = *countO; } @@ -185,13 +186,13 @@ SHAMapStoreImp::SHAMapStoreImp ( { if (setup_.deleteInterval < minimumDeletionInterval_) { - throw std::runtime_error ("online_delete must be at least " + + Throw ("online_delete must be at least " + std::to_string (minimumDeletionInterval_)); } if (setup_.ledgerHistory > setup_.deleteInterval) { - throw std::runtime_error ( + Throw ( "online_delete must be less than ledger_history (currently " + std::to_string (setup_.ledgerHistory) + ")"); } @@ -419,7 +420,7 @@ SHAMapStoreImp::dbPaths() { std::cerr << "node db path must be a directory. " << dbPath.string(); - throw std::runtime_error ( + Throw ( "node db path must be a directory."); } } @@ -465,7 +466,7 @@ SHAMapStoreImp::dbPaths() << get(setup_.nodeDatabase, "path") << std::endl; - throw std::runtime_error ("state db error"); + Throw ("state db error"); } } diff --git a/src/ripple/app/misc/UniqueNodeList.cpp b/src/ripple/app/misc/UniqueNodeList.cpp index d584b3af8..5b5a04677 100644 --- a/src/ripple/app/misc/UniqueNodeList.cpp +++ b/src/ripple/app/misc/UniqueNodeList.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -861,7 +862,7 @@ int UniqueNodeListImp::iSourceScore (ValidatorSource vsWhy) break; default: - throw std::runtime_error ("Internal error: bad ValidatorSource."); + Throw ("Internal error: bad ValidatorSource."); } return iScore; diff --git a/src/ripple/app/misc/impl/AccountTxPaging.cpp b/src/ripple/app/misc/impl/AccountTxPaging.cpp index 977842577..3733d9f2f 100644 --- a/src/ripple/app/misc/impl/AccountTxPaging.cpp +++ b/src/ripple/app/misc/impl/AccountTxPaging.cpp @@ -106,7 +106,7 @@ accountTxPage ( findLedger = token[jss::ledger].asInt(); findSeq = token[jss::seq].asInt(); } - catch (...) + catch (std::exception const&) { return; } diff --git a/src/ripple/app/misc/impl/Transaction.cpp b/src/ripple/app/misc/impl/Transaction.cpp index eae6ff14c..629bf6d34 100644 --- a/src/ripple/app/misc/impl/Transaction.cpp +++ b/src/ripple/app/misc/impl/Transaction.cpp @@ -47,11 +47,6 @@ Transaction::Transaction (std::shared_ptr const& stx, reason = e.what(); return; } - catch (...) - { - reason = "Unexpected exception"; - return; - } mStatus = NEW; } diff --git a/src/ripple/app/paths/Pathfinder.cpp b/src/ripple/app/paths/Pathfinder.cpp index c483a9054..81bde1609 100644 --- a/src/ripple/app/paths/Pathfinder.cpp +++ b/src/ripple/app/paths/Pathfinder.cpp @@ -439,7 +439,7 @@ void Pathfinder::computePathRanks (int maxPaths) << "Default path fails: " << transToken (rc.result ()); } } - catch (...) + catch (std::exception const&) { JLOG (j_.debug) << "Default path causes exception"; } diff --git a/src/ripple/app/paths/cursor/NextIncrement.cpp b/src/ripple/app/paths/cursor/NextIncrement.cpp index 4dbbdb01d..7d555bc31 100644 --- a/src/ripple/app/paths/cursor/NextIncrement.cpp +++ b/src/ripple/app/paths/cursor/NextIncrement.cpp @@ -19,6 +19,7 @@ #include #include +#include #include namespace ripple { @@ -54,7 +55,7 @@ void PathCursor::nextIncrement () const << " inPass()=" << pathState_.inPass(); if (isDry) - throw std::runtime_error ("Made no progress."); + Throw ("Made no progress."); // Calculate relative quality. pathState_.setQuality(getRate ( diff --git a/src/ripple/app/tests/AmendmentTable.test.cpp b/src/ripple/app/tests/AmendmentTable.test.cpp index a8345b13e..0ac338807 100644 --- a/src/ripple/app/tests/AmendmentTable.test.cpp +++ b/src/ripple/app/tests/AmendmentTable.test.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -196,7 +197,7 @@ public: // line above should throw fail ("didn't throw"); } - catch (...) + catch (std::exception const&) { pass (); } @@ -207,7 +208,7 @@ public: // line above should throw fail ("didn't throw"); } - catch (...) + catch (std::exception const&) { pass (); } @@ -233,7 +234,7 @@ public: // line above should throw fail ("didn't throw"); } - catch (...) + catch (std::exception const&) { pass (); } @@ -243,7 +244,7 @@ public: // line above should throw fail ("didn't throw"); } - catch (...) + catch (std::exception const&) { pass (); } @@ -457,28 +458,28 @@ public: case 0: // amendment goes from majority to enabled if (enabled.find (hash) != enabled.end ()) - throw std::runtime_error ("enabling already enabled"); + Throw ("enabling already enabled"); if (majority.find (hash) == majority.end ()) - throw std::runtime_error ("enabling without majority"); + Throw ("enabling without majority"); enabled.insert (hash); majority.erase (hash); break; case tfGotMajority: if (majority.find (hash) != majority.end ()) - throw std::runtime_error ("got majority while having majority"); + Throw ("got majority while having majority"); majority[hash] = roundTime; break; case tfLostMajority: if (majority.find (hash) == majority.end ()) - throw std::runtime_error ("lost majority without majority"); + Throw ("lost majority without majority"); majority.erase (hash); break; default: assert (false); - throw std::runtime_error ("unknown action"); + Throw ("unknown action"); } } } diff --git a/src/ripple/app/tests/Path_test.cpp b/src/ripple/app/tests/Path_test.cpp index 39be3d9c3..153ba3510 100644 --- a/src/ripple/app/tests/Path_test.cpp +++ b/src/ripple/app/tests/Path_test.cpp @@ -18,6 +18,8 @@ //============================================================================== #include +#include +#include #include #include #include @@ -26,7 +28,6 @@ #include #include #include -#include namespace ripple { namespace test { @@ -158,7 +159,7 @@ find_paths(jtx::Env& env, level, saSendMax, convert_all, env.app()); if (! result.first) { - throw std::runtime_error( + Throw ( "Path_test::findPath: ripplePathFind find failed"); } auto const& jv = result.second[0u]; diff --git a/src/ripple/app/tx/impl/CreateOffer.cpp b/src/ripple/app/tx/impl/CreateOffer.cpp index b89078564..d81d1500e 100644 --- a/src/ripple/app/tx/impl/CreateOffer.cpp +++ b/src/ripple/app/tx/impl/CreateOffer.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -322,7 +323,7 @@ CreateOffer::bridged_cross ( assert (!isXRP (taker_amount.in) && !isXRP (taker_amount.out)); if (isXRP (taker_amount.in) || isXRP (taker_amount.out)) - throw std::logic_error ("Bridging with XRP and an endpoint."); + Throw ("Bridging with XRP and an endpoint."); OfferStream offers_direct (view, view_cancel, Book (taker.issue_in (), taker.issue_out ()), @@ -461,7 +462,7 @@ CreateOffer::bridged_cross ( assert (direct_consumed || leg1_consumed || leg2_consumed); if (!direct_consumed && !leg1_consumed && !leg2_consumed) - throw std::logic_error ("bridged crossing: nothing was fully consumed."); + Throw ("bridged crossing: nothing was fully consumed."); } return std::make_pair(cross_result, taker.remaining_offer ()); @@ -542,7 +543,7 @@ CreateOffer::direct_cross ( assert (direct_consumed); if (!direct_consumed) - throw std::logic_error ("direct crossing: nothing was fully consumed."); + Throw ("direct crossing: nothing was fully consumed."); } return std::make_pair(cross_result, taker.remaining_offer ()); @@ -601,11 +602,6 @@ CreateOffer::cross ( j_.error << "Exception during offer crossing: " << e.what (); return std::make_pair (tecINTERNAL, taker.remaining_offer ()); } - catch (...) - { - j_.error << "Exception during offer crossing."; - return std::make_pair (tecINTERNAL, taker.remaining_offer ()); - } } std::string diff --git a/src/ripple/app/tx/impl/Offer.h b/src/ripple/app/tx/impl/Offer.h index c0d88ac12..215e1a864 100644 --- a/src/ripple/app/tx/impl/Offer.h +++ b/src/ripple/app/tx/impl/Offer.h @@ -20,6 +20,7 @@ #ifndef RIPPLE_APP_BOOK_OFFER_H_INCLUDED #define RIPPLE_APP_BOOK_OFFER_H_INCLUDED +#include #include #include #include @@ -99,10 +100,10 @@ public: Amounts const& consumed) const { if (consumed.in > m_amounts.in) - throw std::logic_error ("can't consume more than is available."); + Throw ("can't consume more than is available."); if (consumed.out > m_amounts.out) - throw std::logic_error ("can't produce more than is available."); + Throw ("can't produce more than is available."); m_amounts.in -= consumed.in; m_amounts.out -= consumed.out; diff --git a/src/ripple/app/tx/impl/Taker.cpp b/src/ripple/app/tx/impl/Taker.cpp index 3f004a111..399a2cd10 100644 --- a/src/ripple/app/tx/impl/Taker.cpp +++ b/src/ripple/app/tx/impl/Taker.cpp @@ -19,6 +19,7 @@ #include #include +#include namespace ripple { @@ -401,7 +402,7 @@ BasicTaker::do_cross (Amounts offer, Quality quality, AccountID const& owner) } if (!result.sanity_check ()) - throw std::logic_error ("Computed flow fails sanity check."); + Throw ("Computed flow fails sanity check."); remaining_.out -= result.order.out; remaining_.in -= result.order.in; @@ -476,12 +477,12 @@ BasicTaker::do_cross ( auto flow1 = flow_iou_to_xrp (offer1, quality1, xrp_funds, leg1_in_funds, leg1_rate); if (!flow1.sanity_check ()) - throw std::logic_error ("Computed flow1 fails sanity check."); + Throw ("Computed flow1 fails sanity check."); auto flow2 = flow_xrp_to_iou (offer2, quality2, leg2_out_funds, xrp_funds, leg2_rate); if (!flow2.sanity_check ()) - throw std::logic_error ("Computed flow2 fails sanity check."); + Throw ("Computed flow2 fails sanity check."); // We now have the maximal flows across each leg individually. We need to // equalize them, so that the amount of XRP that flows out of the first leg @@ -505,7 +506,7 @@ BasicTaker::do_cross ( } if (flow1.order.out != flow2.order.in) - throw std::logic_error ("Bridged flow is out of balance."); + Throw ("Bridged flow is out of balance."); remaining_.out -= flow2.order.out; remaining_.in -= flow1.order.in; @@ -555,10 +556,10 @@ void Taker::consume_offer (Offer const& offer, Amounts const& order) { if (order.in < zero) - throw std::logic_error ("flow with negative input."); + Throw ("flow with negative input."); if (order.out < zero) - throw std::logic_error ("flow with negative output."); + Throw ("flow with negative output."); if (journal_.debug) journal_.debug << "Consuming from offer " << offer; @@ -585,7 +586,7 @@ TER Taker::transferXRP ( STAmount const& amount) { if (!isXRP (amount)) - throw std::logic_error ("Using transferXRP with IOU"); + Throw ("Using transferXRP with IOU"); if (from == to) return tesSUCCESS; @@ -603,7 +604,7 @@ TER Taker::redeemIOU ( Issue const& issue) { if (isXRP (amount)) - throw std::logic_error ("Using redeemIOU with XRP"); + Throw ("Using redeemIOU with XRP"); if (account == issue.account) return tesSUCCESS; @@ -615,12 +616,12 @@ TER Taker::redeemIOU ( // If we are trying to redeem some amount, then the account // must have a credit balance. if (get_funds (account, amount) <= zero) - throw std::logic_error ("redeemIOU has no funds to redeem"); + Throw ("redeemIOU has no funds to redeem"); auto ret = ripple::redeemIOU (view_, account, amount, issue, journal_); if (get_funds (account, amount) < zero) - throw std::logic_error ("redeemIOU redeemed more funds than available"); + Throw ("redeemIOU redeemed more funds than available"); return ret; } @@ -631,7 +632,7 @@ TER Taker::issueIOU ( Issue const& issue) { if (isXRP (amount)) - throw std::logic_error ("Using issueIOU with XRP"); + Throw ("Using issueIOU with XRP"); if (account == issue.account) return tesSUCCESS; diff --git a/src/ripple/app/tx/impl/Transactor.cpp b/src/ripple/app/tx/impl/Transactor.cpp index 00732b2c9..647896540 100644 --- a/src/ripple/app/tx/impl/Transactor.cpp +++ b/src/ripple/app/tx/impl/Transactor.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -671,7 +672,7 @@ Transactor::operator()() { // VFALCO Log to journal here // JLOG(journal.fatal) << "invalid fee"; - throw std::logic_error("amount is negative!"); + Throw ("amount is negative!"); } if (fee != zero) diff --git a/src/ripple/app/tx/impl/applySteps.cpp b/src/ripple/app/tx/impl/applySteps.cpp index 11dc1b702..34599cdb5 100644 --- a/src/ripple/app/tx/impl/applySteps.cpp +++ b/src/ripple/app/tx/impl/applySteps.cpp @@ -199,12 +199,6 @@ preflight(Application& app, Rules const& rules, "apply: " << e.what(); return{ pfctx, tefEXCEPTION }; } - catch (...) - { - JLOG(j.fatal) << - "apply: "; - return{ pfctx, tefEXCEPTION }; - } } PreclaimResult @@ -238,12 +232,6 @@ preclaim (PreflightResult const& preflightResult, "apply: " << e.what(); return{ *ctx, tefEXCEPTION, 0 }; } - catch (...) - { - JLOG(ctx->j.fatal) << - "apply: "; - return{ *ctx, tefEXCEPTION, 0 }; - } } std::uint64_t @@ -283,12 +271,6 @@ doApply(PreclaimResult const& preclaimResult, "apply: " << e.what(); return { tefEXCEPTION, false }; } - catch (...) - { - JLOG(preclaimResult.j.fatal) << - "apply: "; - return { tefEXCEPTION, false }; - } } } // ripple \ No newline at end of file diff --git a/src/ripple/basics/BasicConfig.h b/src/ripple/basics/BasicConfig.h index c99668618..e540f201b 100644 --- a/src/ripple/basics/BasicConfig.h +++ b/src/ripple/basics/BasicConfig.h @@ -20,6 +20,7 @@ #ifndef RIPPLE_BASICS_BASICCONFIG_H_INCLUDED #define RIPPLE_BASICS_BASICCONFIG_H_INCLUDED +#include #include #include #include @@ -104,7 +105,7 @@ public: if (lines_.empty ()) return ""; else if (lines_.size () > 1) - throw std::runtime_error ( + Throw ( "A legacy value must have exactly one line. Section: " + name_); return lines_[0]; } @@ -323,7 +324,7 @@ get (Section const& section, { return boost::lexical_cast (result.first); } - catch(...) + catch(std::exception const&) { } return defaultValue; diff --git a/src/ripple/basics/Slice.h b/src/ripple/basics/Slice.h index 9572b8450..4ec05155d 100644 --- a/src/ripple/basics/Slice.h +++ b/src/ripple/basics/Slice.h @@ -20,6 +20,7 @@ #ifndef RIPPLE_BASICS_SLICE_H_INCLUDED #define RIPPLE_BASICS_SLICE_H_INCLUDED +#include #include #include #include @@ -100,7 +101,7 @@ public: operator+= (std::size_t n) { if (n > size_) - throw std::domain_error("too small"); + Throw ("too small"); data_ += n; size_ -= n; return *this; diff --git a/src/ripple/basics/TestSuite.h b/src/ripple/basics/TestSuite.h index e3b1f8fb3..cb6819a9d 100644 --- a/src/ripple/basics/TestSuite.h +++ b/src/ripple/basics/TestSuite.h @@ -110,7 +110,8 @@ public: try { f(); - } catch (...) + } + catch (std::exception const&) { success = true; } diff --git a/src/ripple/basics/contract.h b/src/ripple/basics/contract.h index adfac50a1..7e37da83a 100644 --- a/src/ripple/basics/contract.h +++ b/src/ripple/basics/contract.h @@ -22,6 +22,7 @@ #include #include +#include #include namespace ripple { @@ -32,22 +33,16 @@ namespace ripple { preconditions, postconditions, and invariants. */ -namespace detail { - void -throwException( - std::exception_ptr ep); +Throw (); -} // detail - -template +template void Throw (Args&&... args) { - detail::throwException( - std::make_exception_ptr( - Exception(std::forward< - Args>(args)...))); + static_assert (std::is_convertible::value, + "Exception must derive from std::exception."); + throw E(std::forward(args)...); } /** Called when faulty logic causes a broken invariant. */ @@ -56,11 +51,6 @@ void LogicError ( std::string const& how) noexcept; -/** Called to throw an exception. */ -#ifndef THROW -#define THROW(T, arg) Throw(arg) -#endif - } // ripple #endif diff --git a/src/ripple/basics/impl/CheckLibraryVersions.cpp b/src/ripple/basics/impl/CheckLibraryVersions.cpp index d7e92627d..afa9833d3 100644 --- a/src/ripple/basics/impl/CheckLibraryVersions.cpp +++ b/src/ripple/basics/impl/CheckLibraryVersions.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -58,19 +59,23 @@ std::string openSSLVersion(VersionNumber openSSLVersion) void checkVersion(std::string name, std::string required, std::string actual) { beast::SemanticVersion r, a; - if (!r.parse(required)) { - throw std::runtime_error("Didn't understand required version of " + - name + ": " + required); - } - if (!a.parse(actual)) { - throw std::runtime_error("Didn't understand actual version of " + - name + ": " + required); + if (! r.parse(required)) + { + Throw ( + "Didn't understand required version of " + name + ": " + required); } - if (a < r) { - throw std::runtime_error("Your " + name + " library is out of date.\n" + - "Your version: " + actual + "\n" + - "Required version: " + "\n"); + if (! a.parse(actual)) + { + Throw ( + "Didn't understand actual version of " + name + ": " + required); + } + + if (a < r) + { + Throw ( + "Your " + name + " library is out of date.\n" + "Your version: " + + actual + "\nRequired version: " + required + "\n"); } } diff --git a/src/ripple/basics/impl/StringUtilities.cpp b/src/ripple/basics/impl/StringUtilities.cpp index e12a42ec8..1966aa7c9 100644 --- a/src/ripple/basics/impl/StringUtilities.cpp +++ b/src/ripple/basics/impl/StringUtilities.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -89,14 +90,14 @@ uint64_t uintFromHex (std::string const& strSrc) uint64_t uValue (0); if (strSrc.size () > 16) - throw std::invalid_argument("overlong 64-bit value"); + Throw ("overlong 64-bit value"); for (auto c : strSrc) { int ret = charUnHex (c); if (ret == -1) - throw std::invalid_argument("invalid hex digit"); + Throw ("invalid hex digit"); uValue = (uValue << 4) | ret; } diff --git a/src/ripple/basics/impl/contract.cpp b/src/ripple/basics/impl/contract.cpp index d30f969f3..13384acf1 100644 --- a/src/ripple/basics/impl/contract.cpp +++ b/src/ripple/basics/impl/contract.cpp @@ -36,14 +36,6 @@ accessViolation() noexcept std::abort (); } -// This hook lets you do pre or post -// processing on exceptions to suit needs. -void -throwException (std::exception_ptr ep) -{ - std::rethrow_exception(ep); -} - } // detail [[noreturn]] @@ -53,4 +45,10 @@ LogicError (std::string const&) noexcept detail::accessViolation(); } +void +Throw () +{ + throw; +} + } // ripple diff --git a/src/ripple/basics/impl/make_SSLContext.cpp b/src/ripple/basics/impl/make_SSLContext.cpp index 1615c1344..74d753896 100644 --- a/src/ripple/basics/impl/make_SSLContext.cpp +++ b/src/ripple/basics/impl/make_SSLContext.cpp @@ -18,8 +18,9 @@ //============================================================================== #include -#include #include +#include +#include #include #include #include @@ -81,9 +82,7 @@ static rsa_ptr rsa_generate_key (int n_bits) RSA* rsa = RSA_generate_key (n_bits, RSA_F4, nullptr, nullptr); if (rsa == nullptr) - { - throw std::runtime_error ("RSA_generate_key failed"); - } + Throw ("RSA_generate_key failed"); return rsa_ptr (rsa); } @@ -97,9 +96,7 @@ static evp_pkey_ptr evp_pkey_new() EVP_PKEY* evp_pkey = EVP_PKEY_new(); if (evp_pkey == nullptr) - { - throw std::runtime_error ("EVP_PKEY_new failed"); - } + Throw ("EVP_PKEY_new failed"); return evp_pkey_ptr (evp_pkey); } @@ -107,9 +104,7 @@ static evp_pkey_ptr evp_pkey_new() static void evp_pkey_assign_rsa (EVP_PKEY* evp_pkey, rsa_ptr&& rsa) { if (! EVP_PKEY_assign_RSA (evp_pkey, rsa.get())) - { - throw std::runtime_error ("EVP_PKEY_assign_RSA failed"); - } + Throw ("EVP_PKEY_assign_RSA failed"); rsa.release(); } @@ -123,9 +118,7 @@ static x509_ptr x509_new() X509* x509 = X509_new(); if (x509 == nullptr) - { - throw std::runtime_error ("X509_new failed"); - } + Throw ("X509_new failed"); X509_set_version (x509, NID_X509); @@ -146,25 +139,19 @@ static void x509_set_pubkey (X509* x509, EVP_PKEY* evp_pkey) static void x509_sign (X509* x509, EVP_PKEY* evp_pkey) { if (! X509_sign (x509, evp_pkey, EVP_sha1())) - { - throw std::runtime_error ("X509_sign failed"); - } + Throw ("X509_sign failed"); } static void ssl_ctx_use_certificate (SSL_CTX* const ctx, x509_ptr& cert) { if (SSL_CTX_use_certificate (ctx, cert.release()) <= 0) - { - throw std::runtime_error ("SSL_CTX_use_certificate failed"); - } + Throw ("SSL_CTX_use_certificate failed"); } static void ssl_ctx_use_privatekey (SSL_CTX* const ctx, evp_pkey_ptr& key) { if (SSL_CTX_use_PrivateKey (ctx, key.release()) <= 0) - { - throw std::runtime_error ("SSL_CTX_use_PrivateKey failed"); - } + Throw ("SSL_CTX_use_PrivateKey failed"); } // track when SSL connections have last negotiated @@ -406,7 +393,7 @@ initAnonymous ( context.native_handle (), cipherList.c_str ()); if (result != 1) - throw std::invalid_argument("SSL_CTX_set_cipher_list failed"); + Throw ("SSL_CTX_set_cipher_list failed"); using namespace openssl; @@ -490,7 +477,7 @@ initAuthenticated (boost::asio::ssl::context& context, fclose (f); } - catch (...) + catch (std::exception const&) { fclose (f); beast::FatalError ("Reading the SSL chain file generated an exception.", diff --git a/src/ripple/basics/tests/contract.test.cpp b/src/ripple/basics/tests/contract.test.cpp new file mode 100644 index 000000000..70cf7e209 --- /dev/null +++ b/src/ripple/basics/tests/contract.test.cpp @@ -0,0 +1,62 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2012, 2013 Ripple Labs Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#include +#include +#include +#include + +namespace ripple { + +class contract_test : public beast::unit_test::suite +{ +public: + void run () + { + try + { + Throw("Throw test"); + } + catch (std::runtime_error const& e) + { + expect(std::string(e.what()) == "Throw test"); + + try + { + Throw(); + } + catch (std::runtime_error const& e) + { + expect(std::string(e.what()) == "Throw test"); + } + catch (...) + { + expect(false); + } + } + catch (...) + { + expect(false); + } + } +}; + +BEAST_DEFINE_TESTSUITE(contract,basics,ripple); + +} diff --git a/src/ripple/core/impl/Config.cpp b/src/ripple/core/impl/Config.cpp index cb98cacc9..2d1222d15 100644 --- a/src/ripple/core/impl/Config.cpp +++ b/src/ripple/core/impl/Config.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -267,7 +268,8 @@ void Config::setup (std::string const& strConf, bool bQuiet) boost::filesystem::create_directories (CONFIG_DIR, ec); if (ec) - throw std::runtime_error (boost::str (boost::format ("Can not create %s") % CONFIG_DIR)); + Throw ( + boost::str(boost::format ("Can not create %s") % CONFIG_DIR)); } } @@ -285,7 +287,7 @@ void Config::setup (std::string const& strConf, bool bQuiet) boost::filesystem::create_directories (dataDir, ec); if (ec) - throw std::runtime_error ( + Throw ( boost::str (boost::format ("Can not create %s") % dataDir)); legacy ("database_path", boost::filesystem::absolute (dataDir).string ()); @@ -349,10 +351,11 @@ void Config::loadFromString (std::string const& fileContents) Json::Reader jrReader; Json::Value jvCommand; - if (!jrReader.parse (strJson, jvCommand)) - throw std::runtime_error ( + if (! jrReader.parse (strJson, jvCommand)) + Throw ( boost::str (boost::format ( - "Couldn't parse [" SECTION_RPC_STARTUP "] command: %s") % strJson)); + "Couldn't parse [" SECTION_RPC_STARTUP "] command: %s") + % strJson)); RPC_STARTUP.append (jvCommand); } diff --git a/src/ripple/core/impl/DatabaseCon.cpp b/src/ripple/core/impl/DatabaseCon.cpp index 636b5c2a2..d0a388608 100644 --- a/src/ripple/core/impl/DatabaseCon.cpp +++ b/src/ripple/core/impl/DatabaseCon.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -68,7 +69,7 @@ DatabaseCon::Setup setup_DatabaseCon (Config const& c) void DatabaseCon::setupCheckpointing (JobQueue* q, Logs& l) { if (! q) - throw std::logic_error ("No JobQueue"); + Throw ("No JobQueue"); checkpointer_ = makeCheckpointer (session_, *q, l); } diff --git a/src/ripple/core/impl/DummySociDynamicBackend.cpp b/src/ripple/core/impl/DummySociDynamicBackend.cpp index a5fdde972..d88bf0557 100644 --- a/src/ripple/core/impl/DummySociDynamicBackend.cpp +++ b/src/ripple/core/impl/DummySociDynamicBackend.cpp @@ -25,8 +25,9 @@ */ #include - +#include #include +#include // dummy soci-backend namespace soci { @@ -34,7 +35,8 @@ namespace dynamic_backends { // used internally by session backend_factory const& get (std::string const& name) { - throw std::runtime_error ("Not Supported"); + ripple::Throw ("Not Supported"); + return std::ref(soci::sqlite3); // Silence compiler warning. }; // provided for advanced user-level management diff --git a/src/ripple/core/impl/LoadFeeTrack.cpp b/src/ripple/core/impl/LoadFeeTrack.cpp index 7235e6fe5..ec40ca477 100644 --- a/src/ripple/core/impl/LoadFeeTrack.cpp +++ b/src/ripple/core/impl/LoadFeeTrack.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -75,7 +76,7 @@ LoadFeeTrack::scaleFeeLoad (std::uint64_t fee, std::uint64_t baseFee, // If baseFee * feeFactor overflows, the final result will overflow const auto max = std::numeric_limits::max(); if (baseFee > max / feeFactor) - throw std::overflow_error("scaleFeeLoad"); + Throw ("scaleFeeLoad"); baseFee *= feeFactor; // Reorder fee and baseFee if (fee < baseFee) @@ -86,7 +87,7 @@ LoadFeeTrack::scaleFeeLoad (std::uint64_t fee, std::uint64_t baseFee, // Do the division first, on the larger of fee and baseFee fee /= den; if (fee > max / baseFee) - throw std::overflow_error("scaleFeeLoad"); + Throw ("scaleFeeLoad"); fee *= baseFee; } else diff --git a/src/ripple/core/impl/SociDB.cpp b/src/ripple/core/impl/SociDB.cpp index 42f81f96c..6a358f317 100644 --- a/src/ripple/core/impl/SociDB.cpp +++ b/src/ripple/core/impl/SociDB.cpp @@ -19,6 +19,7 @@ #include +#include #include #include #include @@ -39,9 +40,9 @@ getSociSqliteInit (std::string const& name, { if (dir.empty () || name.empty ()) { - throw std::runtime_error ( + Throw ( "Sqlite databases must specify a dir and a name. Name: " + - name + " Dir: " + dir); + name + " Dir: " + dir); } boost::filesystem::path file (dir); if (is_directory (file)) @@ -57,7 +58,7 @@ getSociInit (BasicConfig const& config, auto const backendName = get(section, "backend", "sqlite"); if (backendName != "sqlite") - throw std::runtime_error ("Unsupported soci backend: " + backendName); + Throw ("Unsupported soci backend: " + backendName); auto const path = config.legacy ("database_path"); auto const ext = dbName == "validators" || dbName == "peerfinder" @@ -103,7 +104,7 @@ void open (soci::session& s, if (beName == "sqlite") s.open(soci::sqlite3, connectionString); else - throw std::runtime_error ("Unsupported soci backend: " + beName); + Throw ("Unsupported soci backend: " + beName); } static @@ -115,7 +116,7 @@ sqlite_api::sqlite3* getConnection (soci::session& s) result = b->conn_; if (! result) - throw std::logic_error ("Didn't get a database connection."); + Throw ("Didn't get a database connection."); return result; } @@ -123,7 +124,7 @@ sqlite_api::sqlite3* getConnection (soci::session& s) size_t getKBUsedAll (soci::session& s) { if (! getConnection (s)) - throw std::logic_error ("No connection found."); + Throw ("No connection found."); return static_cast (sqlite_api::sqlite3_memory_used () / 1024); } @@ -137,7 +138,8 @@ size_t getKBUsedDB (soci::session& s) conn, SQLITE_DBSTATUS_CACHE_USED, &cur, &hiw, 0); return cur / 1024; } - throw std::logic_error (""); + Throw (""); + return 0; // Silence compiler warning. } void convert (soci::blob& from, std::vector& to) @@ -210,7 +212,7 @@ private: if (auto checkpointer = reinterpret_cast (cp)) checkpointer->scheduleCheckpoint(); else - throw std::logic_error ("Didn't get a WALCheckpointer"); + Throw ("Didn't get a WALCheckpointer"); } return SQLITE_OK; } diff --git a/src/ripple/core/tests/Config.test.cpp b/src/ripple/core/tests/Config.test.cpp index cc7cbf907..3e51e65e1 100644 --- a/src/ripple/core/tests/Config.test.cpp +++ b/src/ripple/core/tests/Config.test.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -171,8 +172,8 @@ public: { // Cannot run the test someone created a file where we want to // put out directory - throw std::runtime_error ("Cannot create directory: " + - subDir_.string ()); + Throw ( + "Cannot create directory: " + subDir_.string ()); } } @@ -183,9 +184,9 @@ public: } else { - throw std::runtime_error ( + Throw ( "Refusing to overwrite existing config file: " + - configFile_.string ()); + configFile_.string ()); } rmDataDir_ = !exists (dataDir_); diff --git a/src/ripple/core/tests/SociDB.test.cpp b/src/ripple/core/tests/SociDB.test.cpp index e082dc661..12c6b5b64 100644 --- a/src/ripple/core/tests/SociDB.test.cpp +++ b/src/ripple/core/tests/SociDB.test.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -59,8 +60,8 @@ private: if (!is_directory (dbPath)) { // someone created a file where we want to put out directory - throw std::runtime_error ("Cannot create directory: " + - dbPath.string ()); + Throw ( + "Cannot create directory: " + dbPath.string ()); } } static boost::filesystem::path getDatabasePath () @@ -75,7 +76,7 @@ public: { setupDatabaseDir (getDatabasePath ()); } - catch (...) + catch (std::exception const&) { } } @@ -85,7 +86,7 @@ public: { cleanupDatabaseDir (getDatabasePath ()); } - catch (...) + catch (std::exception const&) { } } diff --git a/src/ripple/crypto/CAutoBN_CTX.h b/src/ripple/crypto/CAutoBN_CTX.h index 70073777c..7db906c81 100644 --- a/src/ripple/crypto/CAutoBN_CTX.h +++ b/src/ripple/crypto/CAutoBN_CTX.h @@ -25,6 +25,8 @@ #ifndef RIPPLE_CRYPTO_CAUTOBN_CTX_H_INCLUDED #define RIPPLE_CRYPTO_CAUTOBN_CTX_H_INCLUDED +#include + #include #include @@ -43,7 +45,7 @@ public: pctx = BN_CTX_new (); if (pctx == nullptr) - throw std::runtime_error ("CAutoBN_CTX : BN_CTX_new() returned nullptr"); + Throw ("CAutoBN_CTX : BN_CTX_new() returned nullptr"); } ~CAutoBN_CTX () diff --git a/src/ripple/crypto/impl/Base58.cpp b/src/ripple/crypto/impl/Base58.cpp index c3a28b50a..0a636837d 100644 --- a/src/ripple/crypto/impl/Base58.cpp +++ b/src/ripple/crypto/impl/Base58.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -89,7 +90,7 @@ std::string Base58::raw_encode (unsigned char const* begin, while (bn > bn0) { if (!BN_div (&dv, &rem, &bn, &bn58, pctx)) - throw std::runtime_error ("EncodeBase58 : BN_div failed"); + Throw ("EncodeBase58 : BN_div failed"); bn = dv; unsigned int c = rem.getuint (); @@ -199,7 +200,7 @@ bool Base58::decode (const char* psz, Blob& vchRet, Alphabet const& alphabet) bnChar.setuint (p1 - alphabet.chars()); if (!BN_mul (&bn, &bn, &bn58, pctx)) - throw std::runtime_error ("DecodeBase58 : BN_mul failed"); + Throw ("DecodeBase58 : BN_mul failed"); bn += bnChar; } diff --git a/src/ripple/crypto/impl/CBigNum.cpp b/src/ripple/crypto/impl/CBigNum.cpp index 553b0fbb5..e3fdce65a 100644 --- a/src/ripple/crypto/impl/CBigNum.cpp +++ b/src/ripple/crypto/impl/CBigNum.cpp @@ -23,6 +23,7 @@ // file license.txt or http://www.opensource.org/licenses/mit-license.php. #include +#include #include #include #include @@ -43,14 +44,14 @@ CBigNum::CBigNum (const CBigNum& b) if (!BN_copy (this, &b)) { BN_clear_free (this); - throw std::runtime_error ("CBigNum::CBigNum(const CBigNum&) : BN_copy failed"); + Throw ("CBigNum::CBigNum(const CBigNum&) : BN_copy failed"); } } CBigNum& CBigNum::operator= (const CBigNum& b) { if (!BN_copy (this, &b)) - throw std::runtime_error ("CBigNum::operator= : BN_copy failed"); + Throw ("CBigNum::operator= : BN_copy failed"); return (*this); } @@ -202,7 +203,7 @@ std::uint64_t CBigNum::getuint64 () const int len = BN_num_bytes (this); if (len > 8) - throw std::runtime_error ("BN getuint64 overflow"); + Throw ("BN getuint64 overflow"); unsigned char buf[8]; memset (buf, 0, sizeof (buf)); @@ -381,7 +382,7 @@ std::string CBigNum::ToString (int nBase) const while (BN_cmp (&bn, &bn0) > 0) { if (!BN_div (&dv, &rem, &bn, &bnBase, pctx)) - throw std::runtime_error ("CBigNum::ToString() : BN_div failed"); + Throw ("CBigNum::ToString() : BN_div failed"); bn = dv; unsigned int c = rem.getuint (); @@ -408,7 +409,7 @@ bool CBigNum::operator! () const CBigNum& CBigNum::operator+= (const CBigNum& b) { if (!BN_add (this, this, &b)) - throw std::runtime_error ("CBigNum::operator+= : BN_add failed"); + Throw ("CBigNum::operator+= : BN_add failed"); return *this; } @@ -424,7 +425,7 @@ CBigNum& CBigNum::operator*= (const CBigNum& b) CAutoBN_CTX pctx; if (!BN_mul (this, this, &b, pctx)) - throw std::runtime_error ("CBigNum::operator*= : BN_mul failed"); + Throw ("CBigNum::operator*= : BN_mul failed"); return *this; } @@ -444,7 +445,7 @@ CBigNum& CBigNum::operator%= (const CBigNum& b) CBigNum& CBigNum::operator<<= (unsigned int shift) { if (!BN_lshift (this, this, shift)) - throw std::runtime_error ("CBigNum:operator<<= : BN_lshift failed"); + Throw ("CBigNum:operator<<= : BN_lshift failed"); return *this; } @@ -462,8 +463,8 @@ CBigNum& CBigNum::operator>>= (unsigned int shift) return *this; } - if (!BN_rshift (this, this, shift)) - throw std::runtime_error ("CBigNum:operator>>= : BN_rshift failed"); + if (! BN_rshift (this, this, shift)) + Throw ("CBigNum:operator>>= : BN_rshift failed"); return *this; } @@ -472,8 +473,8 @@ CBigNum& CBigNum::operator>>= (unsigned int shift) CBigNum& CBigNum::operator++ () { // prefix operator - if (!BN_add (this, this, BN_value_one ())) - throw std::runtime_error ("CBigNum::operator++ : BN_add failed"); + if (! BN_add (this, this, BN_value_one ())) + Throw ("CBigNum::operator++ : BN_add failed"); return *this; } @@ -491,8 +492,8 @@ CBigNum& CBigNum::operator-- () // prefix operator CBigNum r; - if (!BN_sub (&r, this, BN_value_one ())) - throw std::runtime_error ("CBigNum::operator-- : BN_sub failed"); + if (! BN_sub (&r, this, BN_value_one ())) + Throw ("CBigNum::operator-- : BN_sub failed"); *this = r; return *this; @@ -508,8 +509,9 @@ const CBigNum CBigNum::operator-- (int) void CBigNum::setulong (unsigned long n) { - if (!BN_set_word (this, n)) - throw std::runtime_error ("CBigNum conversion from unsigned long : BN_set_word failed"); + if (! BN_set_word (this, n)) + Throw ( + "CBigNum conversion from unsigned long : BN_set_word failed"); } unsigned long CBigNum::getulong () const @@ -521,8 +523,8 @@ const CBigNum operator+ (const CBigNum& a, const CBigNum& b) { CBigNum r; - if (!BN_add (&r, &a, &b)) - throw std::runtime_error ("CBigNum::operator+ : BN_add failed"); + if (! BN_add (&r, &a, &b)) + Throw ("CBigNum::operator+ : BN_add failed"); return r; } @@ -531,8 +533,8 @@ const CBigNum operator- (const CBigNum& a, const CBigNum& b) { CBigNum r; - if (!BN_sub (&r, &a, &b)) - throw std::runtime_error ("CBigNum::operator- : BN_sub failed"); + if (! BN_sub (&r, &a, &b)) + Throw ("CBigNum::operator- : BN_sub failed"); return r; } @@ -549,8 +551,8 @@ const CBigNum operator* (const CBigNum& a, const CBigNum& b) CAutoBN_CTX pctx; CBigNum r; - if (!BN_mul (&r, &a, &b, pctx)) - throw std::runtime_error ("CBigNum::operator* : BN_mul failed"); + if (! BN_mul (&r, &a, &b, pctx)) + Throw ("CBigNum::operator* : BN_mul failed"); return r; } @@ -560,8 +562,8 @@ const CBigNum operator/ (const CBigNum& a, const CBigNum& b) CAutoBN_CTX pctx; CBigNum r; - if (!BN_div (&r, nullptr, &a, &b, pctx)) - throw std::runtime_error ("CBigNum::operator/ : BN_div failed"); + if (! BN_div (&r, nullptr, &a, &b, pctx)) + Throw ("CBigNum::operator/ : BN_div failed"); return r; } @@ -571,8 +573,8 @@ const CBigNum operator% (const CBigNum& a, const CBigNum& b) CAutoBN_CTX pctx; CBigNum r; - if (!BN_mod (&r, &a, &b, pctx)) - throw std::runtime_error ("CBigNum::operator% : BN_div failed"); + if (! BN_mod (&r, &a, &b, pctx)) + Throw ("CBigNum::operator% : BN_div failed"); return r; } @@ -581,8 +583,8 @@ const CBigNum operator<< (const CBigNum& a, unsigned int shift) { CBigNum r; - if (!BN_lshift (&r, &a, shift)) - throw std::runtime_error ("CBigNum:operator<< : BN_lshift failed"); + if (! BN_lshift (&r, &a, shift)) + Throw ("CBigNum:operator<< : BN_lshift failed"); return r; } diff --git a/src/ripple/crypto/impl/ECDSAKey.cpp b/src/ripple/crypto/impl/ECDSAKey.cpp index afa05095e..c94fcfd16 100644 --- a/src/ripple/crypto/impl/ECDSAKey.cpp +++ b/src/ripple/crypto/impl/ECDSAKey.cpp @@ -23,6 +23,7 @@ // file license.txt or http://www.opensource.org/licenses/mit-license.php. #include +#include #include #include #include @@ -36,9 +37,8 @@ static EC_KEY* new_initialized_EC_KEY() EC_KEY* key = EC_KEY_new_by_curve_name (NID_secp256k1); if (key == nullptr) - { - throw std::runtime_error ("new_initialized_EC_KEY() : EC_KEY_new_by_curve_name failed"); - } + Throw ( + "new_initialized_EC_KEY() : EC_KEY_new_by_curve_name failed"); EC_KEY_set_conv_form (key, POINT_CONVERSION_COMPRESSED); @@ -50,9 +50,7 @@ ec_key ECDSAPrivateKey (uint256 const& serialized) BIGNUM* bn = BN_bin2bn (serialized.begin(), serialized.size(), nullptr); if (bn == nullptr) - { - throw std::runtime_error ("ec_key::ec_key: BN_bin2bn failed"); - } + Throw ("ec_key::ec_key: BN_bin2bn failed"); EC_KEY* key = new_initialized_EC_KEY(); ec_key::pointer_t ptr = nullptr; diff --git a/src/ripple/crypto/impl/ECIES.cpp b/src/ripple/crypto/impl/ECIES.cpp index f5deb444b..ef6e08bc0 100644 --- a/src/ripple/crypto/impl/ECIES.cpp +++ b/src/ripple/crypto/impl/ECIES.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -76,18 +77,16 @@ static void getECIESSecret (const openssl::ec_key& secretKey, const openssl::ec_ // Retrieve a secret generated from an EC key pair. At least one private key must be known. if (privkey == nullptr || pubkey == nullptr) - throw std::runtime_error ("missing key"); + Throw ("missing key"); if (! EC_KEY_get0_private_key (privkey)) - { - throw std::runtime_error ("not a private key"); - } + Throw ("not a private key"); unsigned char rawbuf[512]; int buflen = ECDH_compute_key (rawbuf, 512, EC_KEY_get0_public_key (pubkey), privkey, nullptr); if (buflen < ECIES_MIN_SEC) - throw std::runtime_error ("ecdh key failed"); + Throw ("ecdh key failed"); unsigned char hbuf[ECIES_KEY_LENGTH]; ECIES_KEY_HASH (rawbuf, buflen, hbuf); @@ -115,13 +114,13 @@ static ECIES_HMAC_TYPE makeHMAC (const ECIES_HMAC_KEY_TYPE& secret, Blob const& if (HMAC_Init_ex (&ctx, secret.begin (), ECIES_HMAC_KEY_SIZE, ECIES_HMAC_ALGO, nullptr) != 1) { HMAC_CTX_cleanup (&ctx); - throw std::runtime_error ("init hmac"); + Throw ("init hmac"); } if (HMAC_Update (&ctx, & (data.front ()), data.size ()) != 1) { HMAC_CTX_cleanup (&ctx); - throw std::runtime_error ("update hmac"); + Throw ("update hmac"); } ECIES_HMAC_TYPE ret; @@ -130,7 +129,7 @@ static ECIES_HMAC_TYPE makeHMAC (const ECIES_HMAC_KEY_TYPE& secret, Blob const& if (HMAC_Final (&ctx, ret.begin (), &ml) != 1) { HMAC_CTX_cleanup (&ctx); - throw std::runtime_error ("finalize hmac"); + Throw ("finalize hmac"); } assert (ml == ECIES_HMAC_SIZE); @@ -159,7 +158,7 @@ Blob encryptECIES (uint256 const& secretKey, Blob const& publicKey, Blob const& { EVP_CIPHER_CTX_cleanup (&ctx); secret.zero (); - throw std::runtime_error ("init cipher ctx"); + Throw ("init cipher ctx"); } secret.zero (); @@ -178,7 +177,7 @@ Blob encryptECIES (uint256 const& secretKey, Blob const& publicKey, Blob const& if (EVP_EncryptUpdate (&ctx, & (out.front ()) + len, &bytesWritten, hmac.begin (), ECIES_HMAC_SIZE) < 0) { EVP_CIPHER_CTX_cleanup (&ctx); - throw std::runtime_error (""); + Throw (""); } len += bytesWritten; @@ -190,7 +189,7 @@ Blob encryptECIES (uint256 const& secretKey, Blob const& publicKey, Blob const& if (EVP_EncryptUpdate (&ctx, & (out.front ()) + len, &bytesWritten, & (plaintext.front ()), plaintext.size ()) < 0) { EVP_CIPHER_CTX_cleanup (&ctx); - throw std::runtime_error (""); + Throw (""); } len += bytesWritten; @@ -201,7 +200,7 @@ Blob encryptECIES (uint256 const& secretKey, Blob const& publicKey, Blob const& if (EVP_EncryptFinal_ex (&ctx, & (out.front ()) + len, &bytesWritten) < 0) { EVP_CIPHER_CTX_cleanup (&ctx); - throw std::runtime_error ("encryption error"); + Throw ("encryption error"); } len += bytesWritten; @@ -218,7 +217,7 @@ Blob decryptECIES (uint256 const& secretKey, Blob const& publicKey, Blob const& { // minimum ciphertext = IV + HMAC + 1 block if (ciphertext.size () < ((2 * ECIES_ENC_BLK_SIZE) + ECIES_HMAC_SIZE) ) - throw std::runtime_error ("ciphertext too short"); + Throw ("ciphertext too short"); // extract IV ECIES_ENC_IV_TYPE iv; @@ -237,7 +236,7 @@ Blob decryptECIES (uint256 const& secretKey, Blob const& publicKey, Blob const& secret.zero (); hmacKey.zero (); EVP_CIPHER_CTX_cleanup (&ctx); - throw std::runtime_error ("unable to init cipher"); + Throw ("unable to init cipher"); } // decrypt mac @@ -250,7 +249,7 @@ Blob decryptECIES (uint256 const& secretKey, Blob const& publicKey, Blob const& secret.zero (); hmacKey.zero (); EVP_CIPHER_CTX_cleanup (&ctx); - throw std::runtime_error ("unable to extract hmac"); + Throw ("unable to extract hmac"); } // decrypt plaintext (after IV and encrypted mac) @@ -264,7 +263,7 @@ Blob decryptECIES (uint256 const& secretKey, Blob const& publicKey, Blob const& secret.zero (); hmacKey.zero (); EVP_CIPHER_CTX_cleanup (&ctx); - throw std::runtime_error ("unable to extract plaintext"); + Throw ("unable to extract plaintext"); } // decrypt padding @@ -275,7 +274,7 @@ Blob decryptECIES (uint256 const& secretKey, Blob const& publicKey, Blob const& secret.zero (); hmacKey.zero (); EVP_CIPHER_CTX_cleanup (&ctx); - throw std::runtime_error ("plaintext had bad padding"); + Throw ("plaintext had bad padding"); } plaintext.resize (flen + outlen); @@ -286,7 +285,7 @@ Blob decryptECIES (uint256 const& secretKey, Blob const& publicKey, Blob const& secret.zero (); hmacKey.zero (); EVP_CIPHER_CTX_cleanup (&ctx); - throw std::runtime_error ("plaintext had bad hmac"); + Throw ("plaintext had bad hmac"); } secret.zero (); diff --git a/src/ripple/crypto/impl/RandomNumbers.cpp b/src/ripple/crypto/impl/RandomNumbers.cpp index a2ab97a46..1c287a8ea 100644 --- a/src/ripple/crypto/impl/RandomNumbers.cpp +++ b/src/ripple/crypto/impl/RandomNumbers.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -65,7 +66,7 @@ void random_fill (void* buffer, int count) assert (count > 0); if (RAND_bytes (reinterpret_cast (buffer), count) != 1) - throw std::runtime_error ("Insufficient entropy in pool."); + Throw ("Insufficient entropy in pool."); } } diff --git a/src/ripple/crypto/impl/ec_key.cpp b/src/ripple/crypto/impl/ec_key.cpp index b81e1a7ee..fabac916a 100644 --- a/src/ripple/crypto/impl/ec_key.cpp +++ b/src/ripple/crypto/impl/ec_key.cpp @@ -23,6 +23,7 @@ // file license.txt or http://www.opensource.org/licenses/mit-license.php. #include +#include #include #include @@ -45,9 +46,7 @@ ec_key::ec_key (const ec_key& that) ptr = (pointer_t) EC_KEY_dup (get_EC_KEY (that)); if (ptr == nullptr) - { - throw std::runtime_error ("ec_key::ec_key() : EC_KEY_dup failed"); - } + Throw ("ec_key::ec_key() : EC_KEY_dup failed"); EC_KEY_set_conv_form (get_EC_KEY (*this), POINT_CONVERSION_COMPRESSED); } diff --git a/src/ripple/crypto/impl/openssl.cpp b/src/ripple/crypto/impl/openssl.cpp index af16b614e..8792af58b 100644 --- a/src/ripple/crypto/impl/openssl.cpp +++ b/src/ripple/crypto/impl/openssl.cpp @@ -17,6 +17,7 @@ */ //============================================================================== +#include #include #include @@ -26,22 +27,16 @@ namespace openssl { bignum::bignum() { ptr = BN_new(); - if (ptr == nullptr) - { - throw std::runtime_error ("BN_new() failed"); - } + Throw ("BN_new() failed"); } void bignum::assign (uint8_t const* data, size_t size) { // This reuses and assigns ptr BIGNUM* bn = BN_bin2bn (data, size, ptr); - if (bn == nullptr) - { - throw std::runtime_error ("BN_bin2bn() failed"); - } + Throw ("BN_bin2bn() failed"); } void bignum::assign_new (uint8_t const* data, size_t size) @@ -49,31 +44,22 @@ void bignum::assign_new (uint8_t const* data, size_t size) // ptr must not be allocated ptr = BN_bin2bn (data, size, nullptr); - if (ptr == nullptr) - { - throw std::runtime_error ("BN_bin2bn() failed"); - } + Throw ("BN_bin2bn() failed"); } bn_ctx::bn_ctx() { ptr = BN_CTX_new(); - if (ptr == nullptr) - { - throw std::runtime_error ("BN_CTX_new() failed"); - } + Throw ("BN_CTX_new() failed"); } bignum get_order (EC_GROUP const* group, bn_ctx& ctx) { bignum result; - - if (!EC_GROUP_get_order (group, result.get(), ctx.get())) - { - throw std::runtime_error ("EC_GROUP_get_order() failed"); - } + if (! EC_GROUP_get_order (group, result.get(), ctx.get())) + Throw ("EC_GROUP_get_order() failed"); return result; } @@ -81,11 +67,8 @@ bignum get_order (EC_GROUP const* group, bn_ctx& ctx) ec_point::ec_point (EC_GROUP const* group) { ptr = EC_POINT_new (group); - if (ptr == nullptr) - { - throw std::runtime_error ("EC_POINT_new() failed"); - } + Throw ("EC_POINT_new() failed"); } void add_to (EC_GROUP const* group, @@ -94,9 +77,7 @@ void add_to (EC_GROUP const* group, bn_ctx& ctx) { if (!EC_POINT_add (group, b.get(), a.get(), b.get(), ctx.get())) - { - throw std::runtime_error ("EC_POINT_add() failed"); - } + Throw ("EC_POINT_add() failed"); } ec_point multiply (EC_GROUP const* group, @@ -104,11 +85,8 @@ ec_point multiply (EC_GROUP const* group, bn_ctx& ctx) { ec_point result (group); - - if (!EC_POINT_mul (group, result.get(), n.get(), nullptr, nullptr, ctx.get())) - { - throw std::runtime_error ("EC_POINT_mul() failed"); - } + if (! EC_POINT_mul (group, result.get(), n.get(), nullptr, nullptr, ctx.get())) + Throw ("EC_POINT_mul() failed"); return result; } @@ -116,11 +94,8 @@ ec_point multiply (EC_GROUP const* group, ec_point bn2point (EC_GROUP const* group, BIGNUM const* number) { EC_POINT* result = EC_POINT_bn2point (group, number, nullptr, nullptr); - if (result == nullptr) - { - throw std::runtime_error ("EC_POINT_bn2point() failed"); - } + Throw ("EC_POINT_bn2point() failed"); return ec_point::acquire (result); } @@ -129,7 +104,7 @@ static ec_key ec_key_new_secp256k1_compressed() { EC_KEY* key = EC_KEY_new_by_curve_name (NID_secp256k1); - if (key == nullptr) throw std::runtime_error ("EC_KEY_new_by_curve_name() failed"); + if (key == nullptr) Throw ("EC_KEY_new_by_curve_name() failed"); EC_KEY_set_conv_form (key, POINT_CONVERSION_COMPRESSED); @@ -139,11 +114,8 @@ static ec_key ec_key_new_secp256k1_compressed() void serialize_ec_point (ec_point const& point, std::uint8_t* ptr) { ec_key key = ec_key_new_secp256k1_compressed(); - if (EC_KEY_set_public_key((EC_KEY*) key.get(), point.get()) <= 0) - { - throw std::runtime_error ("EC_KEY_set_public_key() failed"); - } + Throw ("EC_KEY_set_public_key() failed"); int const size = i2o_ECPublicKey ((EC_KEY*) key.get(), &ptr); diff --git a/src/ripple/json/Writer.h b/src/ripple/json/Writer.h index e2e692392..962f7f7a8 100644 --- a/src/ripple/json/Writer.h +++ b/src/ripple/json/Writer.h @@ -20,9 +20,10 @@ #ifndef RIPPLE_JSON_WRITER_H_INCLUDED #define RIPPLE_JSON_WRITER_H_INCLUDED +#include #include #include - #include +#include #include namespace Json { @@ -232,8 +233,8 @@ private: inline void check (bool condition, std::string const& message) { - if (!condition) - throw std::logic_error (message); + if (! condition) + ripple::Throw (message); } } // Json diff --git a/src/ripple/json/impl/Object.cpp b/src/ripple/json/impl/Object.cpp index ebd081906..05fbd331c 100644 --- a/src/ripple/json/impl/Object.cpp +++ b/src/ripple/json/impl/Object.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include namespace Json { @@ -61,10 +62,10 @@ Collection::Collection (Collection&& that) noexcept void Collection::checkWritable (std::string const& label) { - if (!enabled_) - throw std::logic_error (label + ": not enabled"); - if (!writer_) - throw std::logic_error (label + ": not writable"); + if (! enabled_) + ripple::Throw (label + ": not enabled"); + if (! writer_) + ripple::Throw (label + ": not writable"); } //------------------------------------------------------------------------------ diff --git a/src/ripple/json/impl/json_assert.h b/src/ripple/json/impl/json_assert.h index 33eb45b9b..ab124d42e 100644 --- a/src/ripple/json/impl/json_assert.h +++ b/src/ripple/json/impl/json_assert.h @@ -22,6 +22,6 @@ #define JSON_ASSERT_UNREACHABLE assert( false ) #define JSON_ASSERT( condition ) assert( condition ); // @todo <= change this into an exception throw -#define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition )) throw std::runtime_error( message ); +#define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition )) ripple::Throw ( message ); #endif diff --git a/src/ripple/json/impl/json_reader.cpp b/src/ripple/json/impl/json_reader.cpp index 3e2777e16..90ffed648 100644 --- a/src/ripple/json/impl/json_reader.cpp +++ b/src/ripple/json/impl/json_reader.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -949,7 +950,8 @@ std::istream& operator>> ( std::istream& sin, Value& root ) bool ok = reader.parse (sin, root); //JSON_ASSERT( ok ); - if (!ok) throw std::runtime_error (reader.getFormatedErrorMessages ()); + if (! ok) + ripple::Throw (reader.getFormatedErrorMessages ()); return sin; } diff --git a/src/ripple/json/impl/json_value.cpp b/src/ripple/json/impl/json_value.cpp index a72ae7d66..ef349eda5 100644 --- a/src/ripple/json/impl/json_value.cpp +++ b/src/ripple/json/impl/json_value.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include diff --git a/src/ripple/ledger/impl/TxMeta.cpp b/src/ripple/ledger/impl/TxMeta.cpp index b82335030..6d0d986c0 100644 --- a/src/ripple/ledger/impl/TxMeta.cpp +++ b/src/ripple/ledger/impl/TxMeta.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -194,7 +195,8 @@ STObject& TxMeta::getAffectedNode (uint256 const& node) return n; } assert (false); - throw std::runtime_error ("Affected node not found"); + Throw ("Affected node not found"); + return *(mNodes.begin()); // Silence compiler warning. } const STObject& TxMeta::peekAffectedNode (uint256 const& node) const @@ -205,7 +207,8 @@ const STObject& TxMeta::peekAffectedNode (uint256 const& node) const return n; } - throw std::runtime_error ("Affected node not found"); + Throw ("Affected node not found"); + return *(mNodes.begin()); // Silence compiler warning. } void TxMeta::init (uint256 const& id, std::uint32_t ledger) diff --git a/src/ripple/net/impl/HTTPClient.cpp b/src/ripple/net/impl/HTTPClient.cpp index 536fc43aa..2d2db74ee 100644 --- a/src/ripple/net/impl/HTTPClient.cpp +++ b/src/ripple/net/impl/HTTPClient.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -50,8 +51,10 @@ public: m_context.set_default_verify_paths (ec); if (ec && config.SSL_VERIFY_DIR.empty ()) - throw std::runtime_error (boost::str ( - boost::format ("Failed to set_default_verify_paths: %s") % ec.message ())); + Throw ( + boost::str (boost::format ( + "Failed to set_default_verify_paths: %s") % + ec.message ())); } else { @@ -63,8 +66,9 @@ public: m_context.add_verify_path (config.SSL_VERIFY_DIR, ec); if (ec) - throw std::runtime_error (boost::str ( - boost::format ("Failed to add verify path: %s") % ec.message ())); + Throw ( + boost::str (boost::format ( + "Failed to add verify path: %s") % ec.message ())); } } diff --git a/src/ripple/net/impl/RPCCall.cpp b/src/ripple/net/impl/RPCCall.cpp index 41dcc3444..50635f96e 100644 --- a/src/ripple/net/impl/RPCCall.cpp +++ b/src/ripple/net/impl/RPCCall.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -1039,11 +1040,14 @@ struct RPCCallImp // Receive reply if (iStatus == 401) - throw std::runtime_error ("incorrect rpcuser or rpcpassword (authorization failed)"); + Throw ( + "incorrect rpcuser or rpcpassword (authorization failed)"); else if ((iStatus >= 400) && (iStatus != 400) && (iStatus != 404) && (iStatus != 500)) // ? - throw std::runtime_error (std::string ("server returned HTTP error ") + std::to_string (iStatus)); + Throw ( + std::string ("server returned HTTP error ") + + std::to_string (iStatus)); else if (strData.empty ()) - throw std::runtime_error ("no response from server"); + Throw ("no response from server"); // Parse reply JLOG (j.debug) << "RPC reply: " << strData << std::endl; @@ -1052,10 +1056,10 @@ struct RPCCallImp Json::Value jvReply; if (!reader.parse (strData, jvReply)) - throw std::runtime_error ("couldn't parse reply from server"); + Throw ("couldn't parse reply from server"); if (!jvReply) - throw std::runtime_error ("expected reply to have result, error and id properties"); + Throw ("expected reply to have result, error and id properties"); Json::Value jvResult (Json::objectValue); @@ -1130,7 +1134,7 @@ int fromCommandLine ( std::stringstream ss; setup = setup_ServerHandler(config, ss); } - catch(...) + catch (std::exception const&) { // ignore any exceptions, so the command // line client works without a config file @@ -1214,12 +1218,6 @@ int fromCommandLine ( jvOutput["error_what"] = e.what (); nRet = rpcINTERNAL; } - catch (...) - { - jvOutput = rpcError (rpcINTERNAL); - jvOutput["error_what"] = "exception"; - nRet = rpcINTERNAL; - } std::cout << jvOutput.toStyledString (); diff --git a/src/ripple/net/impl/RPCSub.cpp b/src/ripple/net/impl/RPCSub.cpp index a6f396c6f..b6d4a2f27 100644 --- a/src/ripple/net/impl/RPCSub.cpp +++ b/src/ripple/net/impl/RPCSub.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -49,19 +50,13 @@ public: std::string strScheme; if (!parseUrl (strUrl, strScheme, mIp, mPort, mPath)) - { - throw std::runtime_error ("Failed to parse url."); - } + Throw ("Failed to parse url."); else if (strScheme == "https") - { - mSSL = true; - } + mSSL = true; else if (strScheme != "http") - { - throw std::runtime_error ("Only http and https is supported."); - } + Throw ("Only http and https is supported."); - mSeq = 1; + mSeq = 1; if (mPort < 0) mPort = mSSL ? 443 : 80; diff --git a/src/ripple/nodestore/backend/MemoryFactory.cpp b/src/ripple/nodestore/backend/MemoryFactory.cpp index 3ededb8ea..c11fe8eae 100644 --- a/src/ripple/nodestore/backend/MemoryFactory.cpp +++ b/src/ripple/nodestore/backend/MemoryFactory.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -63,7 +64,7 @@ public: std::make_tuple(path), std::make_tuple()); MemoryDB& db = result.first->second; if (db.open) - throw std::runtime_error("already open"); + Throw ("already open"); return db; } }; @@ -88,7 +89,7 @@ public: , journal_ (journal) { if (name_.empty()) - throw std::runtime_error ("Missing path in Memory backend"); + Throw ("Missing path in Memory backend"); db_ = &memoryFactory.open(name_); } @@ -137,7 +138,7 @@ public: std::vector> fetchBatch (std::size_t n, void const* const* keys) override { - throw std::runtime_error("pure virtual called"); + Throw ("pure virtual called"); return {}; } diff --git a/src/ripple/nodestore/backend/NuDBFactory.cpp b/src/ripple/nodestore/backend/NuDBFactory.cpp index 5375e9e21..a4bc65cc0 100644 --- a/src/ripple/nodestore/backend/NuDBFactory.cpp +++ b/src/ripple/nodestore/backend/NuDBFactory.cpp @@ -19,6 +19,7 @@ #include +#include #include #include #include @@ -71,7 +72,7 @@ public: , scheduler_ (scheduler) { if (name_.empty()) - throw std::runtime_error ( + Throw ( "nodestore: Missing path in NuDB backend"); auto const folder = boost::filesystem::path (name_); boost::filesystem::create_directories (folder); @@ -85,13 +86,10 @@ public: 0.50); try { - if (! db_.open (dp, kp, lp, - arena_alloc_size)) - throw std::runtime_error( - "nodestore: open failed"); + if (! db_.open (dp, kp, lp, arena_alloc_size)) + Throw ("nodestore: open failed"); if (db_.appnum() != currentType) - throw std::runtime_error( - "nodestore: unknown appnum"); + Throw ("nodestore: unknown appnum"); } catch (std::exception const& e) { @@ -157,7 +155,7 @@ public: std::vector> fetchBatch (std::size_t n, void const* const* keys) override { - throw std::runtime_error("pure virtual called"); + Throw ("pure virtual called"); return {}; } diff --git a/src/ripple/nodestore/backend/NullFactory.cpp b/src/ripple/nodestore/backend/NullFactory.cpp index 85ef88096..63957f8b6 100644 --- a/src/ripple/nodestore/backend/NullFactory.cpp +++ b/src/ripple/nodestore/backend/NullFactory.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -62,7 +63,7 @@ public: std::vector> fetchBatch (std::size_t n, void const* const* keys) override { - throw std::runtime_error("pure virtual called"); + Throw ("pure virtual called"); return {}; } diff --git a/src/ripple/nodestore/backend/RocksDBFactory.cpp b/src/ripple/nodestore/backend/RocksDBFactory.cpp index 6e836f852..a772fbaf8 100644 --- a/src/ripple/nodestore/backend/RocksDBFactory.cpp +++ b/src/ripple/nodestore/backend/RocksDBFactory.cpp @@ -23,6 +23,7 @@ #if RIPPLE_ROCKSDB_AVAILABLE +#include #include // VFALCO Bad dependency #include #include @@ -107,8 +108,8 @@ public: , m_scheduler (scheduler) , m_batch (*this, scheduler) { - if (!get_if_exists(keyValues, "path", m_name)) - throw std::runtime_error ("Missing path in RocksDBFactory backend"); + if (! get_if_exists(keyValues, "path", m_name)) + Throw ("Missing path in RocksDBFactory backend"); rocksdb::Options options; rocksdb::BlockBasedTableOptions table_options; @@ -170,8 +171,9 @@ public: rocksdb::DB* db = nullptr; rocksdb::Status status = rocksdb::DB::Open (options, m_name, &db); - if (!status.ok () || !db) - throw std::runtime_error (std::string("Unable to open/create RocksDB: ") + status.ToString()); + if (! status.ok () || ! db) + Throw ( + std::string("Unable to open/create RocksDB: ") + status.ToString()); m_db.reset (db); } @@ -262,7 +264,7 @@ public: std::vector> fetchBatch (std::size_t n, void const* const* keys) override { - throw std::runtime_error("pure virtual called"); + Throw ("pure virtual called"); return {}; } @@ -294,8 +296,8 @@ public: auto ret = m_db->Write (options, &wb); - if (!ret.ok ()) - throw std::runtime_error ("storeBatch failed: " + ret.ToString()); + if (! ret.ok ()) + Throw ("storeBatch failed: " + ret.ToString()); } void diff --git a/src/ripple/nodestore/backend/RocksDBQuickFactory.cpp b/src/ripple/nodestore/backend/RocksDBQuickFactory.cpp index 0582ffca3..f99468e1a 100644 --- a/src/ripple/nodestore/backend/RocksDBQuickFactory.cpp +++ b/src/ripple/nodestore/backend/RocksDBQuickFactory.cpp @@ -23,6 +23,7 @@ #if RIPPLE_ROCKSDB_AVAILABLE +#include #include // VFALCO Bad dependency #include #include @@ -103,7 +104,8 @@ public: , m_name (get(keyValues, "path")) { if (m_name.empty()) - throw std::runtime_error ("Missing path in RocksDBQuickFactory backend"); + Throw ( + "Missing path in RocksDBQuickFactory backend"); // Defaults std::uint64_t budget = 512 * 1024 * 1024; // 512MB @@ -167,8 +169,10 @@ public: rocksdb::DB* db = nullptr; rocksdb::Status status = rocksdb::DB::Open (options, m_name, &db); - if (!status.ok () || !db) - throw std::runtime_error (std::string("Unable to open/create RocksDBQuick: ") + status.ToString()); + if (! status.ok () || ! db) + Throw ( + std::string("Unable to open/create RocksDBQuick: ") + + status.ToString()); m_db.reset (db); } @@ -265,7 +269,7 @@ public: std::vector> fetchBatch (std::size_t n, void const* const* keys) override { - throw std::runtime_error("pure virtual called"); + Throw ("pure virtual called"); return {}; } @@ -294,8 +298,8 @@ public: auto ret = m_db->Write (options, &wb); - if (!ret.ok ()) - throw std::runtime_error ("storeBatch failed: " + ret.ToString()); + if (! ret.ok ()) + Throw ("storeBatch failed: " + ret.ToString()); } void diff --git a/src/ripple/nodestore/impl/ManagerImp.cpp b/src/ripple/nodestore/impl/ManagerImp.cpp index 901db17a7..2bebe6136 100644 --- a/src/ripple/nodestore/impl/ManagerImp.cpp +++ b/src/ripple/nodestore/impl/ManagerImp.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -39,7 +40,7 @@ ManagerImp::instance() void ManagerImp::missing_backend() { - throw std::runtime_error ( + Throw ( "Your rippled.cfg is missing a [node_db] entry, " "please see the rippled-example.cfg file!" ); diff --git a/src/ripple/nodestore/impl/codec.h b/src/ripple/nodestore/impl/codec.h index 2db493b92..b3a871475 100644 --- a/src/ripple/nodestore/impl/codec.h +++ b/src/ripple/nodestore/impl/codec.h @@ -20,6 +20,7 @@ #ifndef RIPPLE_NODESTORE_CODEC_H_INCLUDED #define RIPPLE_NODESTORE_CODEC_H_INCLUDED +#include #include #include #include @@ -62,14 +63,14 @@ snappy_decompress (void const* in, if (! snappy::GetUncompressedLength( reinterpret_cast(in), in_size, &result.second)) - throw beast::nudb::codec_error( + Throw ( "snappy decompress"); void* const out = bf(result.second); result.first = out; if (! snappy::RawUncompress( reinterpret_cast(in), in_size, reinterpret_cast(out))) - throw beast::nudb::codec_error( + Throw ( "snappy decompress"); return result; } @@ -87,7 +88,7 @@ lz4_decompress (void const* in, auto const n = read_varint( p, in_size, result.second); if (n == 0) - throw codec_error( + Throw ( "lz4 decompress"); void* const out = bf(result.second); result.first = out; @@ -95,7 +96,7 @@ lz4_decompress (void const* in, reinterpret_cast(in) + n, reinterpret_cast(out), result.second) + n != in_size) - throw codec_error( + Throw ( "lz4 decompress"); return result; } @@ -123,7 +124,7 @@ lz4_compress (void const* in, reinterpret_cast(out + n), in_size); if (out_size == 0) - throw codec_error( + Throw ( "lz4 compress"); result.second = n + out_size; return result; @@ -154,7 +155,7 @@ nodeobject_decompress (void const* in, auto const vn = read_varint( p, in_size, type); if (vn == 0) - throw codec_error( + Throw ( "nodeobject decompress"); p += vn; in_size -= vn; @@ -179,7 +180,7 @@ nodeobject_decompress (void const* in, auto const hs = field::size; // Mask if (in_size < hs + 32) - throw codec_error( + Throw ( "nodeobject codec: short inner node"); istream is(p, in_size); std::uint16_t mask; @@ -194,7 +195,7 @@ nodeobject_decompress (void const* in, write (os, hotUNKNOWN); write(os, HashPrefix::innerNode); if (mask == 0) - throw codec_error( + Throw ( "nodeobject codec: empty inner node"); std::uint16_t bit = 0x8000; for (int i = 16; i--; bit >>= 1) @@ -202,7 +203,7 @@ nodeobject_decompress (void const* in, if (mask & bit) { if (in_size < 32) - throw codec_error( + Throw ( "nodeobject codec: short inner node"); std::memcpy(os.data(32), is(32), 32); in_size -= 32; @@ -213,14 +214,14 @@ nodeobject_decompress (void const* in, } } if (in_size > 0) - throw codec_error( + Throw ( "nodeobject codec: long inner node"); break; } case 3: // full inner node { if (in_size != 16 * 32) // hashes - throw codec_error( + Throw ( "nodeobject codec: short full inner node"); istream is(p, in_size); result.second = 525; @@ -235,7 +236,7 @@ nodeobject_decompress (void const* in, break; } default: - throw codec_error( + Throw ( "nodeobject codec: bad type=" + std::to_string(type)); }; @@ -366,7 +367,7 @@ nodeobject_compress (void const* in, break; } default: - throw std::logic_error( + Throw ( "nodeobject codec: unknown=" + std::to_string(type)); }; diff --git a/src/ripple/nodestore/tests/Timing.test.cpp b/src/ripple/nodestore/tests/Timing.test.cpp index 344d5cab4..163cb1f86 100644 --- a/src/ripple/nodestore/tests/Timing.test.cpp +++ b/src/ripple/nodestore/tests/Timing.test.cpp @@ -312,12 +312,12 @@ public: parallel_for(params.items, params.threads, std::ref(*this), std::ref(*backend)); } - catch(...) + catch (std::exception const&) { #if NODESTORE_TIMING_DO_VERIFY backend->verify(); #endif - throw; + Throw(); } backend->close(); } @@ -373,12 +373,12 @@ public: parallel_for_id(params.items, params.threads, std::ref(*this), std::ref(params), std::ref(*backend)); } - catch(...) + catch (std::exception const&) { #if NODESTORE_TIMING_DO_VERIFY backend->verify(); #endif - throw; + Throw(); } backend->close(); } @@ -436,12 +436,12 @@ public: parallel_for_id(params.items, params.threads, std::ref(*this), std::ref(params), std::ref(*backend)); } - catch(...) + catch (std::exception const&) { #if NODESTORE_TIMING_DO_VERIFY backend->verify(); #endif - throw; + Throw(); } backend->close(); } @@ -514,12 +514,12 @@ public: parallel_for_id(params.items, params.threads, std::ref(*this), std::ref(params), std::ref(*backend)); } - catch(...) + catch (std::exception const&) { #if NODESTORE_TIMING_DO_VERIFY backend->verify(); #endif - throw; + Throw(); } backend->close(); } @@ -626,12 +626,12 @@ public: parallel_for_id(params.items, params.threads, std::ref(*this), std::ref(params), std::ref(*backend)); } - catch(...) + catch (std::exception const&) { #if NODESTORE_TIMING_DO_VERIFY backend->verify(); #endif - throw; + Throw(); } backend->close(); } diff --git a/src/ripple/nodestore/tests/import_test.cpp b/src/ripple/nodestore/tests/import_test.cpp index 3cd254152..0adaf54fb 100644 --- a/src/ripple/nodestore/tests/import_test.cpp +++ b/src/ripple/nodestore/tests/import_test.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -280,12 +281,12 @@ parse_args(std::string const& s) { boost::smatch m; if (! boost::regex_match (kv, m, re1)) - throw std::runtime_error( + Throw ( "invalid parameter " + kv); auto const result = map.emplace(m[1], m[2]); if (! result.second) - throw std::runtime_error( + Throw ( "duplicate parameter " + m[1]); } return map; @@ -379,7 +380,7 @@ public: rocksdb::DB::OpenForReadOnly( options, from_path, &pdb); if (! status.ok () || ! pdb) - throw std::runtime_error ( + Throw ( "Can't open '" + from_path + "': " + status.ToString()); db.reset(pdb); @@ -413,7 +414,7 @@ public: for (it->SeekToFirst (); it->Valid (); it->Next()) { if (it->key().size() != 32) - throw std::runtime_error( + Throw ( "Unexpected key size " + std::to_string(it->key().size())); void const* const key = it->key().data(); @@ -829,7 +830,7 @@ read (File& f, dat_file_header& dh) } catch (file_short_read_error const&) { - throw store_corrupt_error( + Throw ( "short data file header"); } istream is(buf); @@ -888,7 +889,7 @@ read (File& f, key_file_header& kh) } catch (file_short_read_error const&) { - throw store_corrupt_error( + Throw ( "short key file header"); } istream is(buf); diff --git a/src/ripple/overlay/impl/Manifest.cpp b/src/ripple/overlay/impl/Manifest.cpp index 61f234866..5dd8647e8 100644 --- a/src/ripple/overlay/impl/Manifest.cpp +++ b/src/ripple/overlay/impl/Manifest.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -46,7 +47,7 @@ make_Manifest (std::string s) } return Manifest (std::move (s), *opt_pk, *opt_spk, *opt_seq); } - catch (...) + catch (std::exception const&) { return boost::none; } @@ -125,25 +126,25 @@ ManifestCache::configValidatorKey( if (words.size () != 2) { - throw std::runtime_error ("[validator_keys] format is ` "); + Throw ("[validator_keys] format is ` "); } Blob key; if (! Base58::decodeWithCheck (words[0], key)) { - throw std::runtime_error ("Error decoding validator key"); + Throw ("Error decoding validator key"); } if (key.size() != 34) { - throw std::runtime_error ("Expected 34-byte validator key"); + Throw ("Expected 34-byte validator key"); } if (key[0] != TOKEN_NODE_PUBLIC) { - throw std::runtime_error ("Expected TOKEN_NODE_PUBLIC (28)"); + Throw ("Expected TOKEN_NODE_PUBLIC (28)"); } if (key[1] != 0xED) { - throw std::runtime_error ("Expected Ed25519 key (0xED)"); + Throw ("Expected Ed25519 key (0xED)"); } auto const masterKey = PublicKey (Slice(key.data() + 1, key.size() - 1)); @@ -159,16 +160,16 @@ void ManifestCache::configManifest ( Manifest m, UniqueNodeList& unl, beast::Journal journal) { - if (!m.verify()) + if (! m.verify()) { - throw std::runtime_error("Unverifiable manifest in config"); + Throw ("Unverifiable manifest in config"); } auto const result = applyManifest (std::move(m), unl, journal); if (result != ManifestDisposition::accepted) { - throw std::runtime_error("Our own validation manifest was not accepted"); + Throw ("Our own validation manifest was not accepted"); } } @@ -181,7 +182,7 @@ ManifestCache::addTrustedKey (PublicKey const& pk, std::string comment) if (value.m) { - throw std::runtime_error ( + Throw ( "New trusted validator key already has a manifest"); } @@ -352,7 +353,7 @@ void ManifestCache::load ( { if (!mo->verify()) { - throw std::runtime_error("Unverifiable manifest in db"); + Throw ("Unverifiable manifest in db"); } // add trusted key map_[mo->masterKey]; diff --git a/src/ripple/overlay/impl/OverlayImpl.cpp b/src/ripple/overlay/impl/OverlayImpl.cpp index d0aac43fd..e7c6bdabd 100644 --- a/src/ripple/overlay/impl/OverlayImpl.cpp +++ b/src/ripple/overlay/impl/OverlayImpl.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -466,7 +467,7 @@ OverlayImpl::setupValidatorKeyManifests (BasicConfig const& config, } else { - throw std::runtime_error("Malformed manifest in config"); + Throw ("Malformed manifest in config"); } } else @@ -532,7 +533,7 @@ OverlayImpl::onPrepare() { if (addr.port () == 0) { - throw std::runtime_error ("Port not specified for " + Throw ("Port not specified for " "address:" + addr.to_string ()); } @@ -1070,7 +1071,7 @@ setup_Overlay (BasicConfig const& config) beast::IP::Address::from_string (ip); if (! valid || ! setup.public_ip.is_v4() || is_private (setup.public_ip)) - throw std::runtime_error ("Configured public IP is invalid"); + Throw ("Configured public IP is invalid"); } return setup; } diff --git a/src/ripple/overlay/impl/PeerImp.cpp b/src/ripple/overlay/impl/PeerImp.cpp index a7ef59f92..0776713ae 100644 --- a/src/ripple/overlay/impl/PeerImp.cpp +++ b/src/ripple/overlay/impl/PeerImp.cpp @@ -1119,7 +1119,7 @@ PeerImp::onMessage (std::shared_ptr const& m) }); } } - catch (...) + catch (std::exception const&) { p_journal_.warning << "Transaction invalid: " << strHex(m->rawtransaction ()); @@ -1614,12 +1614,6 @@ PeerImp::onMessage (std::shared_ptr const& m) "Validation: Exception, " << e.what(); fee_ = Resource::feeInvalidRequest; } - catch (...) - { - p_journal_.warning << - "Validation: Unknown exception"; - fee_ = Resource::feeInvalidRequest; - } } void @@ -1880,7 +1874,7 @@ PeerImp::checkTransaction (int flags, app_.getOPs ().processTransaction ( tx, trusted, false, NetworkOPs::FailHard::no); } - catch (...) + catch (std::exception const&) { app_.getHashRouter ().setFlags (stx->getTransactionID (), SF_BAD); charge (Resource::feeBadData); @@ -1957,7 +1951,7 @@ PeerImp::checkValidation (STValidation::pointer val, val, std::to_string(id()))) overlay_.relay(*packet, signingHash); } - catch (...) + catch (std::exception const&) { p_journal_.trace << "Exception processing validation"; diff --git a/src/ripple/overlay/tests/manifest_test.cpp b/src/ripple/overlay/tests/manifest_test.cpp index 827f7d172..92c57fb8b 100644 --- a/src/ripple/overlay/tests/manifest_test.cpp +++ b/src/ripple/overlay/tests/manifest_test.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -55,7 +56,7 @@ private: if (!is_directory (dbPath)) { // someone created a file where we want to put our directory - throw std::runtime_error ("Cannot create directory: " + + Throw ("Cannot create directory: " + dbPath.string ()); } } @@ -70,7 +71,7 @@ public: { setupDatabaseDir (getDatabasePath ()); } - catch (...) + catch (std::exception const&) { } } @@ -80,7 +81,7 @@ public: { cleanupDatabaseDir (getDatabasePath ()); } - catch (...) + catch (std::exception const&) { } } @@ -110,10 +111,9 @@ public: std::string const m (static_cast (s.data()), s.size()); if (auto r = ripple::make_Manifest (std::move (m))) - { return std::move (*r); - } - throw std::runtime_error("Could not create a manifest"); + Throw ("Could not create a manifest"); + return *ripple::make_Manifest(std::move(m)); // Silence compiler warning. } Manifest diff --git a/src/ripple/peerfinder/impl/Logic.h b/src/ripple/peerfinder/impl/Logic.h index 5524b00be..88aff6cdb 100644 --- a/src/ripple/peerfinder/impl/Logic.h +++ b/src/ripple/peerfinder/impl/Logic.h @@ -20,6 +20,7 @@ #ifndef RIPPLE_PEERFINDER_LOGIC_H_INCLUDED #define RIPPLE_PEERFINDER_LOGIC_H_INCLUDED +#include #include #include #include @@ -189,7 +190,7 @@ public: { if (remote_address.port () == 0) { - throw std::runtime_error ("Port not specified for address:" + + Throw ("Port not specified for address:" + remote_address.to_string ()); } diff --git a/src/ripple/peerfinder/impl/StoreSqdb.h b/src/ripple/peerfinder/impl/StoreSqdb.h index beaf233eb..b76537660 100644 --- a/src/ripple/peerfinder/impl/StoreSqdb.h +++ b/src/ripple/peerfinder/impl/StoreSqdb.h @@ -20,6 +20,7 @@ #ifndef RIPPLE_PEERFINDER_STORESQDB_H_INCLUDED #define RIPPLE_PEERFINDER_STORESQDB_H_INCLUDED +#include #include #include #include @@ -161,7 +162,7 @@ public: "Updating database to version " << currentSchemaVersion; else if (version > currentSchemaVersion) { - throw std::runtime_error ( + Throw ( "The PeerFinder database version is higher than expected"); } } diff --git a/src/ripple/protocol/KnownFormats.h b/src/ripple/protocol/KnownFormats.h index 7974814a3..173dcd7d6 100644 --- a/src/ripple/protocol/KnownFormats.h +++ b/src/ripple/protocol/KnownFormats.h @@ -20,6 +20,7 @@ #ifndef RIPPLE_PROTOCOL_KNOWNFORMATS_H_INCLUDED #define RIPPLE_PROTOCOL_KNOWNFORMATS_H_INCLUDED +#include #include #include @@ -110,13 +111,9 @@ public: Item const* const result = findByName (name); if (result != nullptr) - { return result->getType (); - } - else - { - throw std::runtime_error ("Unknown format name"); - } + Throw ("Unknown format name"); + return {}; // Silence compiler warning. } /** Retrieve a format based on its type. diff --git a/src/ripple/protocol/STBase.h b/src/ripple/protocol/STBase.h index 3f6af5972..a664e3cb3 100644 --- a/src/ripple/protocol/STBase.h +++ b/src/ripple/protocol/STBase.h @@ -20,6 +20,7 @@ #ifndef RIPPLE_PROTOCOL_STBASE_H_INCLUDED #define RIPPLE_PROTOCOL_STBASE_H_INCLUDED +#include #include #include #include @@ -91,7 +92,7 @@ public: { D* ptr = dynamic_cast (this); if (ptr == nullptr) - throw std::bad_cast(); + Throw (); return *ptr; } @@ -101,7 +102,7 @@ public: { D const * ptr = dynamic_cast (this); if (ptr == nullptr) - throw std::bad_cast(); + Throw (); return *ptr; } diff --git a/src/ripple/protocol/STExchange.h b/src/ripple/protocol/STExchange.h index 7b44fb041..ac322cc5e 100644 --- a/src/ripple/protocol/STExchange.h +++ b/src/ripple/protocol/STExchange.h @@ -21,6 +21,7 @@ #define RIPPLE_PROTOCOL_STEXCHANGE_H_INCLUDED #include +#include #include #include #include @@ -139,7 +140,7 @@ get (STObject const& st, dynamic_cast(b); // This should never happen if (! u) - throw std::runtime_error ( + Throw ( "Wrong field type"); STExchange::get(t, *u); return t; diff --git a/src/ripple/protocol/STObject.h b/src/ripple/protocol/STObject.h index 892a68871..6cb3625b8 100644 --- a/src/ripple/protocol/STObject.h +++ b/src/ripple/protocol/STObject.h @@ -533,8 +533,8 @@ public: { STBase* rf = getPField (field, true); - if (!rf) - throw std::runtime_error ("Field not found"); + if (! rf) + Throw ("Field not found"); if (rf->getSType () == STI_NOTPRESENT) rf = makeFieldPresent (field); @@ -543,7 +543,7 @@ public: if (auto cf = dynamic_cast (rf)) cf->setValue (v); else - throw std::runtime_error ("Wrong field type"); + Throw ("Wrong field type"); } STObject& peekFieldObject (SField const& field); @@ -594,8 +594,8 @@ private: { const STBase* rf = peekAtPField (field); - if (!rf) - throw std::runtime_error ("Field not found"); + if (! rf) + Throw ("Field not found"); SerializedTypeID id = rf->getSType (); @@ -604,8 +604,8 @@ private: const T* cf = dynamic_cast (rf); - if (!cf) - throw std::runtime_error ("Wrong field type"); + if (! cf) + Throw ("Wrong field type"); return cf->value (); } @@ -620,8 +620,8 @@ private: { const STBase* rf = peekAtPField (field); - if (!rf) - throw std::runtime_error ("Field not found"); + if (! rf) + Throw ("Field not found"); SerializedTypeID id = rf->getSType (); @@ -630,8 +630,8 @@ private: const T* cf = dynamic_cast (rf); - if (!cf) - throw std::runtime_error ("Wrong field type"); + if (! cf) + Throw ("Wrong field type"); return *cf; } @@ -644,16 +644,16 @@ private: STBase* rf = getPField (field, true); - if (!rf) - throw std::runtime_error ("Field not found"); + if (! rf) + Throw ("Field not found"); if (rf->getSType () == STI_NOTPRESENT) rf = makeFieldPresent (field); T* cf = dynamic_cast (rf); - if (!cf) - throw std::runtime_error ("Wrong field type"); + if (! cf) + Throw ("Wrong field type"); cf->setValue (std::move (value)); } @@ -664,16 +664,16 @@ private: { STBase* rf = getPField (field, true); - if (!rf) - throw std::runtime_error ("Field not found"); + if (! rf) + Throw ("Field not found"); if (rf->getSType () == STI_NOTPRESENT) rf = makeFieldPresent (field); T* cf = dynamic_cast (rf); - if (!cf) - throw std::runtime_error ("Wrong field type"); + if (! cf) + Throw ("Wrong field type"); (*cf) = value; } @@ -684,16 +684,16 @@ private: { STBase* rf = getPField (field, true); - if (!rf) - throw std::runtime_error ("Field not found"); + if (! rf) + Throw ("Field not found"); if (rf->getSType () == STI_NOTPRESENT) rf = makeFieldPresent (field); T* cf = dynamic_cast (rf); - if (!cf) - throw std::runtime_error ("Wrong field type"); + if (! cf) + Throw ("Wrong field type"); return *cf; } @@ -710,7 +710,7 @@ STObject::Proxy::Proxy (STObject* st, TypedField const* f) { // STObject has associated template if (! st_->peekAtPField(*f_)) - THROW(template_field_error, *f); + Throw (*f); style_ = st_->mType->style(*f_); } else @@ -728,7 +728,7 @@ STObject::Proxy::value() const -> if (t) return t->value(); if (style_ != SOE_DEFAULT) - THROW(missing_field_error, *f_); + Throw (*f_); return value_type{}; } @@ -884,7 +884,7 @@ STObject::OptionalProxy::disengage() { if (this->style_ == SOE_REQUIRED || this->style_ == SOE_DEFAULT) - THROW(template_field_error, *this->f_); + Throw (*this->f_); if (this->style_ == SOE_INVALID) this->st_->delField(*this->f_); else @@ -911,7 +911,7 @@ STObject::operator[](TypedField const& f) const if (! b) // This is a free object (no constraints) // with no template - THROW(missing_field_error, f); + Throw (f); auto const u = dynamic_cast(b); if (! u) @@ -919,7 +919,7 @@ STObject::operator[](TypedField const& f) const assert(mType); assert(b->getSType() == STI_NOTPRESENT); if(mType->style(f) == SOE_OPTIONAL) - THROW(missing_field_error, f); + Throw (f); assert(mType->style(f) == SOE_DEFAULT); // Handle the case where value_type is a // const reference, otherwise we return diff --git a/src/ripple/protocol/Serializer.h b/src/ripple/protocol/Serializer.h index 09119fc57..b49683ad1 100644 --- a/src/ripple/protocol/Serializer.h +++ b/src/ripple/protocol/Serializer.h @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -386,7 +387,7 @@ SerialIter::getBitString() base_uint u; auto const n = Bits/8; if (remain_ < n) - throw std::runtime_error( + Throw ( "invalid SerialIter getBitString"); std::memcpy (u.begin(), p_, n); p_ += n; diff --git a/src/ripple/protocol/impl/ErrorCodes.cpp b/src/ripple/protocol/impl/ErrorCodes.cpp index 27b34fe5f..7714bfef9 100644 --- a/src/ripple/protocol/impl/ErrorCodes.cpp +++ b/src/ripple/protocol/impl/ErrorCodes.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -132,7 +133,7 @@ private: std::forward_as_tuple (code), std::forward_as_tuple ( code, token, message))); if (! result.second) - throw std::invalid_argument ("duplicate error code"); + Throw ("duplicate error code"); } private: diff --git a/src/ripple/protocol/impl/IOUAmount.cpp b/src/ripple/protocol/impl/IOUAmount.cpp index ea688747e..125aeff9b 100644 --- a/src/ripple/protocol/impl/IOUAmount.cpp +++ b/src/ripple/protocol/impl/IOUAmount.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -56,7 +57,7 @@ IOUAmount::normalize () while (mantissa_ > maxMantissa) { if (exponent_ >= maxExponent) - throw std::overflow_error ("IOUAmount::normalize"); + Throw ("IOUAmount::normalize"); mantissa_ /= 10; ++exponent_; @@ -69,7 +70,7 @@ IOUAmount::normalize () } if (exponent_ > maxExponent) - throw std::overflow_error ("value overflow"); + Throw ("value overflow"); if (negative) mantissa_ = -mantissa_; diff --git a/src/ripple/protocol/impl/RippleAddress.cpp b/src/ripple/protocol/impl/RippleAddress.cpp index 7c4a436f6..838d26d04 100644 --- a/src/ripple/protocol/impl/RippleAddress.cpp +++ b/src/ripple/protocol/impl/RippleAddress.cpp @@ -18,8 +18,8 @@ //============================================================================== #include +#include #include -#include #include #include #include @@ -151,20 +151,15 @@ RippleAddress::toPublicKey() const return RipplePublicKey (vchData.begin(), vchData.end()); } -static -std::runtime_error badSourceError (int nVersion) -{ - return std::runtime_error ("bad source: " + std::to_string (nVersion)); -} - NodeID RippleAddress::getNodeID () const { switch (nVersion) { case TOKEN_NONE: - throw std::runtime_error ("unset source - getNodeID"); + Throw ("unset source - getNodeID"); - case TOKEN_NODE_PUBLIC: { + case TOKEN_NODE_PUBLIC: + { // Note, we are encoding the left. NodeID node; node.copyFrom(Hash160 (vchData)); @@ -172,8 +167,9 @@ NodeID RippleAddress::getNodeID () const } default: - throw badSourceError (nVersion); + Throw ("bad source: " + std::to_string(nVersion)); } + return {}; // Silence compiler warning. } Blob const& RippleAddress::getNodePublic () const @@ -181,14 +177,15 @@ Blob const& RippleAddress::getNodePublic () const switch (nVersion) { case TOKEN_NONE: - throw std::runtime_error ("unset source - getNodePublic"); + Throw ("unset source - getNodePublic"); case TOKEN_NODE_PUBLIC: return vchData; default: - throw badSourceError (nVersion); + Throw("bad source: " + std::to_string(nVersion)); } + return vchData; // Silence compiler warning. } std::string RippleAddress::humanNodePublic () const @@ -196,14 +193,15 @@ std::string RippleAddress::humanNodePublic () const switch (nVersion) { case TOKEN_NONE: - throw std::runtime_error ("unset source - humanNodePublic"); + Throw ("unset source - humanNodePublic"); case TOKEN_NODE_PUBLIC: return ToString (); default: - throw badSourceError (nVersion); + Throw("bad source: " + std::to_string(nVersion)); } + return {}; // Silence compiler warning. } bool RippleAddress::setNodePublic (std::string const& strPublic) @@ -253,14 +251,15 @@ Blob const& RippleAddress::getNodePrivateData () const switch (nVersion) { case TOKEN_NONE: - throw std::runtime_error ("unset source - getNodePrivateData"); + Throw ("unset source - getNodePrivateData"); case TOKEN_NODE_PRIVATE: return vchData; default: - throw badSourceError (nVersion); + Throw ("bad source: " + std::to_string(nVersion)); } + return vchData; // Silence compiler warning. } uint256 RippleAddress::getNodePrivate () const @@ -268,14 +267,15 @@ uint256 RippleAddress::getNodePrivate () const switch (nVersion) { case TOKEN_NONE: - throw std::runtime_error ("unset source = getNodePrivate"); + Throw ("unset source = getNodePrivate"); case TOKEN_NODE_PRIVATE: return uint256 (vchData); default: - throw badSourceError (nVersion); + Throw ("bad source: " + std::to_string(nVersion)); } + return {}; // Silence compiler warning. } std::string RippleAddress::humanNodePrivate () const @@ -283,14 +283,15 @@ std::string RippleAddress::humanNodePrivate () const switch (nVersion) { case TOKEN_NONE: - throw std::runtime_error ("unset source - humanNodePrivate"); + Throw ("unset source - humanNodePrivate"); case TOKEN_NODE_PRIVATE: return ToString (); default: - throw badSourceError (nVersion); + Throw ("bad source: " + std::to_string(nVersion)); } + return {}; // Silence compiler warning. } bool RippleAddress::setNodePrivate (std::string const& strPrivate) @@ -320,7 +321,7 @@ void RippleAddress::signNodePrivate (uint256 const& hash, Blob& vchSig) const vchSig = ECDSASign (hash, getNodePrivate()); if (vchSig.empty()) - throw std::runtime_error ("Signing failed."); + Throw ("Signing failed."); } // @@ -342,18 +343,18 @@ Blob const& RippleAddress::getAccountPublic () const switch (nVersion) { case TOKEN_NONE: - throw std::runtime_error ("unset source - getAccountPublic"); + Throw ("unset source - getAccountPublic"); case TOKEN_ACCOUNT_ID: - throw std::runtime_error ("public not available from account id"); - break; + Throw ("public not available from account id"); case TOKEN_ACCOUNT_PUBLIC: return vchData; default: - throw badSourceError (nVersion); + Throw ("bad source: " + std::to_string(nVersion)); } + return vchData; // Silence compiler warning. } std::string RippleAddress::humanAccountPublic () const @@ -361,17 +362,18 @@ std::string RippleAddress::humanAccountPublic () const switch (nVersion) { case TOKEN_NONE: - throw std::runtime_error ("unset source - humanAccountPublic"); + Throw ("unset source - humanAccountPublic"); case TOKEN_ACCOUNT_ID: - throw std::runtime_error ("public not available from account id"); + Throw ("public not available from account id"); case TOKEN_ACCOUNT_PUBLIC: return ToString (); default: - throw badSourceError (nVersion); + Throw ("bad source: " + std::to_string(nVersion)); } + return {}; // Silence compiler warning. } bool RippleAddress::setAccountPublic (std::string const& strPublic) @@ -437,14 +439,15 @@ uint256 RippleAddress::getAccountPrivate () const switch (nVersion) { case TOKEN_NONE: - throw std::runtime_error ("unset source - getAccountPrivate"); + Throw ("unset source - getAccountPrivate"); case TOKEN_ACCOUNT_SECRET: return uint256::fromVoid (vchData.data() + (vchData.size() - 32)); default: - throw badSourceError (nVersion); + Throw ("bad source: " + std::to_string(nVersion)); } + return {}; // Silence compiler warning. } bool RippleAddress::setAccountPrivate (std::string const& strPrivate) @@ -518,7 +521,7 @@ Blob RippleAddress::accountPrivateEncrypt ( { vucCipherText = encryptECIES (secretKey, publicKey, vucPlainText); } - catch (...) + catch (std::exception const&) { // TODO: log this or explain why this is unimportant! } @@ -540,7 +543,7 @@ Blob RippleAddress::accountPrivateDecrypt ( { vucPlainText = decryptECIES (secretKey, publicKey, vucCipherText); } - catch (...) + catch (std::exception const&) { // TODO: log this or explain why this is unimportant! } @@ -559,15 +562,16 @@ Blob const& RippleAddress::getGenerator () const switch (nVersion) { case TOKEN_NONE: - throw std::runtime_error ("unset source - getGenerator"); + Throw ("unset source - getGenerator"); case TOKEN_FAMILY_GENERATOR: // Do nothing. return vchData; default: - throw badSourceError (nVersion); + Throw ("bad source: " + std::to_string(nVersion)); } + return vchData; // Silence compiler warning. } std::string RippleAddress::humanGenerator () const @@ -575,14 +579,15 @@ std::string RippleAddress::humanGenerator () const switch (nVersion) { case TOKEN_NONE: - throw std::runtime_error ("unset source - humanGenerator"); + Throw ("unset source - humanGenerator"); case TOKEN_FAMILY_GENERATOR: return ToString (); default: - throw badSourceError (nVersion); + Throw ("bad source: " + std::to_string(nVersion)); } + return {}; // Silence compiler warning. } void RippleAddress::setGenerator (Blob const& vPublic) @@ -607,14 +612,15 @@ uint128 RippleAddress::getSeed () const switch (nVersion) { case TOKEN_NONE: - throw std::runtime_error ("unset source - getSeed"); + Throw ("unset source - getSeed"); case TOKEN_FAMILY_SEED: return uint128 (vchData); default: - throw badSourceError (nVersion); + Throw ("bad source: " + std::to_string(nVersion)); } + return {}; // Silence compiler warning. } std::string RippleAddress::humanSeed1751 () const @@ -622,7 +628,7 @@ std::string RippleAddress::humanSeed1751 () const switch (nVersion) { case TOKEN_NONE: - throw std::runtime_error ("unset source - humanSeed1751"); + Throw ("unset source - humanSeed1751"); case TOKEN_FAMILY_SEED: { @@ -641,8 +647,9 @@ std::string RippleAddress::humanSeed1751 () const } default: - throw badSourceError (nVersion); + Throw ("bad source: " + std::to_string(nVersion)); } + return {}; // Silence compiler warning. } std::string RippleAddress::humanSeed () const @@ -650,14 +657,15 @@ std::string RippleAddress::humanSeed () const switch (nVersion) { case TOKEN_NONE: - throw std::runtime_error ("unset source - humanSeed"); + Throw ("unset source - humanSeed"); case TOKEN_FAMILY_SEED: return ToString (); default: - throw badSourceError (nVersion); + Throw ("bad source: " + std::to_string(nVersion)); } + return {}; // Silence compiler warning. } int RippleAddress::setSeed1751 (std::string const& strHuman1751) diff --git a/src/ripple/protocol/impl/STAmount.cpp b/src/ripple/protocol/impl/STAmount.cpp index 381a3c97d..4746ccebf 100644 --- a/src/ripple/protocol/impl/STAmount.cpp +++ b/src/ripple/protocol/impl/STAmount.cpp @@ -45,7 +45,7 @@ std::int64_t getSNValue (STAmount const& amount) { if (!amount.native ()) - throw std::runtime_error ("amount is not native!"); + Throw ("amount is not native!"); auto ret = static_cast(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 ("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 ("invalid native currency"); issue.account.copyFrom (sit.get160 ()); if (isXRP (issue.account)) - throw std::runtime_error ("invalid native account"); + Throw ("invalid native account"); // 10 bits for the offset, sign and "not native" flag int offset = static_cast(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 ("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 ("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 ("Cannot return non-native STAmount as XRPAmount"); auto drops = static_cast (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 ("Cannot return native STAmount as IOUAmount"); auto mantissa = static_cast (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 ("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 ("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 ("value overflow"); mValue /= 10; ++mOffset; @@ -689,7 +689,7 @@ void STAmount::canonicalize () } if (mOffset > cMaxOffset) - throw std::runtime_error ("value overflow"); + Throw ("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 ("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 ("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 ("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 ("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 ("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 ("invalid currency"); if (! issuer.isString () || !to_issuer (issue.account, issuer.asString ())) - throw std::runtime_error ("invalid issuer"); + Throw ("invalid issuer"); if (isXRP (issue.currency)) - throw std::runtime_error ("invalid issuer"); + Throw ("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 ("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 ("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 ("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 ("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 ("Native value overflow"); if (((maxV >> 32) * minV) > 2095475792ull) // cMaxNative / 2^32 - throw std::runtime_error ("Native value overflow"); + Throw ("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 ("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 ("Native value overflow"); if (((maxV >> 32) * minV) > 2095475792ull) // cMaxNative / 2^32 - throw std::runtime_error ("Native value overflow"); + Throw ("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 ("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 ("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 ("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 ("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 ("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 ("mulDiv"); return value * mul; } return value * mul / div; diff --git a/src/ripple/protocol/impl/STArray.cpp b/src/ripple/protocol/impl/STArray.cpp index 614c7b9ae..76f664206 100644 --- a/src/ripple/protocol/impl/STArray.cpp +++ b/src/ripple/protocol/impl/STArray.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -77,7 +78,7 @@ STArray::STArray (SerialIter& sit, SField const& f) { WriteLog (lsWARNING, STObject) << "Encountered array with end of object marker"; - throw std::runtime_error ("Illegal terminator in array"); + Throw ("Illegal terminator in array"); } auto const& fn = SField::getField (type, field); @@ -86,13 +87,13 @@ STArray::STArray (SerialIter& sit, SField const& f) { WriteLog (lsTRACE, STObject) << "Unknown field: " << type << "/" << field; - throw std::runtime_error ("Unknown field"); + Throw ("Unknown field"); } if (fn.fieldType != STI_OBJECT) { WriteLog (lsTRACE, STObject) << "Array contains non-object"; - throw std::runtime_error ("Non-object in array"); + Throw ("Non-object in array"); } v_.emplace_back(fn); @@ -100,7 +101,7 @@ STArray::STArray (SerialIter& sit, SField const& f) if (v_.back().setTypeFromSField (fn) == STObject::typeSetFail) { - throw std::runtime_error ("Malformed object in array"); + Throw ("Malformed object in array"); } } } diff --git a/src/ripple/protocol/impl/STLedgerEntry.cpp b/src/ripple/protocol/impl/STLedgerEntry.cpp index 1b4f43a31..c49d0f2ff 100644 --- a/src/ripple/protocol/impl/STLedgerEntry.cpp +++ b/src/ripple/protocol/impl/STLedgerEntry.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -36,7 +37,7 @@ STLedgerEntry::STLedgerEntry (Keylet const& k) mFormat = LedgerFormats::getInstance().findByType (type_); if (mFormat == nullptr) - throw std::runtime_error ("invalid ledger entry type"); + Throw ("invalid ledger entry type"); set (mFormat->elements); setFieldU16 (sfLedgerEntryType, static_cast (mFormat->getType ())); @@ -72,7 +73,7 @@ void STLedgerEntry::setSLEType () static_cast (getFieldU16 (sfLedgerEntryType))); if (mFormat == nullptr) - throw std::runtime_error ("invalid ledger entry type"); + Throw ("invalid ledger entry type"); type_ = mFormat->getType (); if (!setType (mFormat->elements)) @@ -80,7 +81,7 @@ void STLedgerEntry::setSLEType () WriteLog (lsWARNING, SerializedLedger) << "Ledger entry not valid for type " << mFormat->getName (); WriteLog (lsWARNING, SerializedLedger) << getJson (0); - throw std::runtime_error ("ledger entry not valid for type"); + Throw ("ledger entry not valid for type"); } } diff --git a/src/ripple/protocol/impl/STObject.cpp b/src/ripple/protocol/impl/STObject.cpp index c4d960378..d969379a1 100644 --- a/src/ripple/protocol/impl/STObject.cpp +++ b/src/ripple/protocol/impl/STObject.cpp @@ -210,7 +210,7 @@ bool STObject::set (SerialIter& sit, int depth) { WriteLog (lsWARNING, STObject) << "Encountered object with end of array marker"; - throw std::runtime_error ("Illegal terminator in object"); + Throw ("Illegal terminator in object"); } if (!reachedEndOfObject) @@ -224,7 +224,7 @@ bool STObject::set (SerialIter& sit, int depth) WriteLog (lsWARNING, STObject) << "Unknown field: field_type=" << type << ", field_name=" << field; - throw std::runtime_error ("Unknown field"); + Throw ("Unknown field"); } // Unflatten the field @@ -234,7 +234,7 @@ bool STObject::set (SerialIter& sit, int depth) STObject* const obj = dynamic_cast (&(v_.back().get())); if (obj && (obj->setTypeFromSField (fn) == typeSetFail)) { - throw std::runtime_error ("field deserialization error"); + Throw ("field deserialization error"); } } } @@ -352,7 +352,7 @@ const STBase& STObject::peekAtField (SField const& field) const int index = getFieldIndex (field); if (index == -1) - throw std::runtime_error ("Field not found"); + Throw ("Field not found"); return peekAtIndex (index); } @@ -362,7 +362,7 @@ STBase& STObject::getField (SField const& field) int index = getFieldIndex (field); if (index == -1) - throw std::runtime_error ("Field not found"); + Throw ("Field not found"); return getIndex (index); } @@ -462,7 +462,7 @@ STBase* STObject::makeFieldPresent (SField const& field) if (index == -1) { if (!isFree ()) - throw std::runtime_error ("Field not found"); + Throw ("Field not found"); return getPIndex (emplace_back(detail::nonPresentObject, field)); } @@ -482,7 +482,7 @@ void STObject::makeFieldAbsent (SField const& field) int index = getFieldIndex (field); if (index == -1) - throw std::runtime_error ("Field not found"); + Throw ("Field not found"); const STBase& f = peekAtIndex (index); @@ -512,7 +512,7 @@ std::string STObject::getFieldString (SField const& field) const { const STBase* rf = peekAtPField (field); - if (!rf) throw std::runtime_error ("Field not found"); + if (! rf) Throw ("Field not found"); return rf->getText (); } @@ -606,7 +606,7 @@ STObject::set (std::unique_ptr v) else { if (! isFree()) - throw std::runtime_error( + Throw ( "missing field in templated STObject"); v_.emplace_back(std::move(*v)); } diff --git a/src/ripple/protocol/impl/STParsedJSON.cpp b/src/ripple/protocol/impl/STParsedJSON.cpp index 66a5ba648..d0abbb285 100644 --- a/src/ripple/protocol/impl/STParsedJSON.cpp +++ b/src/ripple/protocol/impl/STParsedJSON.cpp @@ -18,8 +18,8 @@ //============================================================================== #include +#include #include -#include #include #include #include @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -46,7 +47,7 @@ template static T range_check_cast (U value, T minimum, T maximum) { if ((value < minimum) || (value > maximum)) - throw std::runtime_error ("Value out of range"); + Throw ("Value out of range"); return static_cast (value); } @@ -212,7 +213,7 @@ static boost::optional parseLeaf ( return ret; } } - catch (...) + catch (std::exception const&) { error = invalid_data (json_name, fieldName); return ret; @@ -282,7 +283,7 @@ static boost::optional parseLeaf ( return ret; } } - catch (...) + catch (std::exception const&) { error = invalid_data (json_name, fieldName); return ret; @@ -316,7 +317,7 @@ static boost::optional parseLeaf ( return ret; } } - catch (...) + catch (std::exception const&) { error = invalid_data (json_name, fieldName); return ret; @@ -349,7 +350,7 @@ static boost::optional parseLeaf ( return ret; } } - catch (...) + catch (std::exception const&) { error = invalid_data (json_name, fieldName); return ret; @@ -370,7 +371,7 @@ static boost::optional parseLeaf ( return ret; } } - catch (...) + catch (std::exception const&) { error = invalid_data (json_name, fieldName); return ret; @@ -391,7 +392,7 @@ static boost::optional parseLeaf ( return ret; } } - catch (...) + catch (std::exception const&) { error = invalid_data (json_name, fieldName); return ret; @@ -412,7 +413,7 @@ static boost::optional parseLeaf ( return ret; } } - catch (...) + catch (std::exception const&) { error = invalid_data (json_name, fieldName); return ret; @@ -431,13 +432,13 @@ static boost::optional parseLeaf ( { std::pair vBlob (strUnHex (value.asString ())); - if (!vBlob.second) - throw std::invalid_argument ("invalid data"); + if (! vBlob.second) + Throw ("invalid data"); ret = detail::make_stvar (field, vBlob.first.data (), vBlob.first.size ()); } - catch (...) + catch (std::exception const&) { error = invalid_data (json_name, fieldName); return ret; @@ -450,7 +451,7 @@ static boost::optional parseLeaf ( { ret = detail::make_stvar (amountFromJson (field, value)); } - catch (...) + catch (std::exception const&) { error = invalid_data (json_name, fieldName); return ret; @@ -476,7 +477,7 @@ static boost::optional parseLeaf ( } ret = detail::make_stvar (std::move (tail)); } - catch (...) + catch (std::exception const&) { error = invalid_data (json_name, fieldName); return ret; @@ -606,7 +607,7 @@ static boost::optional parseLeaf ( } ret = detail::make_stvar (std::move (tail)); } - catch (...) + catch (std::exception const&) { error = invalid_data (json_name, fieldName); return ret; @@ -638,7 +639,7 @@ static boost::optional parseLeaf ( ret = detail::make_stvar ( field, *account); } - catch (...) + catch (std::exception const&) { error = invalid_data (json_name, fieldName); return ret; @@ -721,7 +722,7 @@ static boost::optional parseObject ( return boost::none; data.emplace_back (std::move (*ret)); } - catch (...) + catch (std::exception const&) { error = invalid_data (json_name, fieldName); return boost::none; @@ -739,7 +740,7 @@ static boost::optional parseObject ( return boost::none; data.emplace_back (std::move (*array)); } - catch (...) + catch (std::exception const&) { error = invalid_data (json_name, fieldName); return boost::none; @@ -846,7 +847,7 @@ static boost::optional parseArray ( return detail::make_stvar (std::move (tail)); } - catch (...) + catch (std::exception const&) { error = invalid_data (json_name); return boost::none; diff --git a/src/ripple/protocol/impl/STPathSet.cpp b/src/ripple/protocol/impl/STPathSet.cpp index b6206bda9..a8fec73de 100644 --- a/src/ripple/protocol/impl/STPathSet.cpp +++ b/src/ripple/protocol/impl/STPathSet.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -65,7 +66,7 @@ STPathSet::STPathSet (SerialIter& sit, SField const& name) { WriteLog (lsINFO, STBase) << "STPathSet: Empty path."; - throw std::runtime_error ("empty path"); + Throw ("empty path"); } push_back (path); @@ -79,7 +80,7 @@ STPathSet::STPathSet (SerialIter& sit, SField const& name) WriteLog (lsINFO, STBase) << "STPathSet: Bad path element: " << iType; - throw std::runtime_error ("bad path element"); + Throw ("bad path element"); } else { diff --git a/src/ripple/protocol/impl/STTx.cpp b/src/ripple/protocol/impl/STTx.cpp index 506b7942c..6aa04a5cd 100644 --- a/src/ripple/protocol/impl/STTx.cpp +++ b/src/ripple/protocol/impl/STTx.cpp @@ -49,7 +49,7 @@ STTx::STTx (TxType type) { WriteLog (lsWARNING, STTx) << "Transaction type: " << type; - throw std::runtime_error ("invalid transaction type"); + Throw ("invalid transaction type"); } set (format->elements); @@ -67,14 +67,14 @@ STTx::STTx (STObject&& object) { WriteLog (lsWARNING, STTx) << "Transaction type: " << tx_type_; - throw std::runtime_error ("invalid transaction type"); + Throw ("invalid transaction type"); } if (!setType (format->elements)) { WriteLog (lsWARNING, STTx) << "Transaction not legal for format"; - throw std::runtime_error ("transaction not valid"); + Throw ("transaction not valid"); } tid_ = getHash(HashPrefix::transactionID); @@ -89,7 +89,7 @@ STTx::STTx (SerialIter& sit) { WriteLog (lsERROR, STTx) << "Transaction has invalid length: " << length; - throw std::runtime_error ("Transaction length invalid"); + Throw ("Transaction length invalid"); } set (sit); @@ -101,14 +101,14 @@ STTx::STTx (SerialIter& sit) { WriteLog (lsWARNING, STTx) << "Invalid transaction type: " << tx_type_; - throw std::runtime_error ("invalid transaction type"); + Throw ("invalid transaction type"); } if (!setType (format->elements)) { WriteLog (lsWARNING, STTx) << "Transaction not legal for format"; - throw std::runtime_error ("transaction not valid"); + Throw ("transaction not valid"); } tid_ = getHash(HashPrefix::transactionID); @@ -178,7 +178,7 @@ Blob STTx::getSignature () const { return getFieldVL (sfTxnSignature); } - catch (...) + catch (std::exception const&) { return Blob (); } @@ -210,7 +210,7 @@ bool STTx::checkSign(bool allowMultiSign) const sigGood = checkSingleSign (); } } - catch (...) + catch (std::exception const&) { } return sigGood; @@ -298,7 +298,7 @@ STTx::checkSingleSign () const ret = n.accountPublicVerify (getSigningData (*this), getFieldVL (sfTxnSignature), fullyCanonical); } - catch (...) + catch (std::exception const&) { // Assume it was a signature failure. ret = false; @@ -372,7 +372,7 @@ STTx::checkMultiSign () const validSig = pubKey.accountPublicVerify ( s.getData(), signature, fullyCanonical); } - catch (...) + catch (std::exception const&) { // We assume any problem lies with the signature. validSig = false; diff --git a/src/ripple/protocol/impl/STValidation.cpp b/src/ripple/protocol/impl/STValidation.cpp index 90d090543..315b2827b 100644 --- a/src/ripple/protocol/impl/STValidation.cpp +++ b/src/ripple/protocol/impl/STValidation.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -35,7 +36,7 @@ STValidation::STValidation (SerialIter& sit, bool checkSignature) if (checkSignature && !isValid ()) { WriteLog (lsTRACE, Ledger) << "Invalid validation " << getJson (0); - throw std::runtime_error ("Invalid validation"); + Throw ("Invalid validation"); } } @@ -104,7 +105,7 @@ bool STValidation::isValid (uint256 const& signingHash) const return raPublicKey.isValid () && raPublicKey.verifyNodePublic (signingHash, getFieldVL (sfSignature), fullyCanonical); } - catch (...) + catch (std::exception const&) { WriteLog (lsINFO, Ledger) << "exception validating validation"; return false; diff --git a/src/ripple/protocol/impl/STVar.cpp b/src/ripple/protocol/impl/STVar.cpp index aaa21b19c..4f7c067d0 100644 --- a/src/ripple/protocol/impl/STVar.cpp +++ b/src/ripple/protocol/impl/STVar.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -142,7 +143,7 @@ STVar::STVar (SerialIter& sit, SField const& name) case STI_OBJECT: construct(sit, name); return; case STI_ARRAY: construct(sit, name); return; default: - throw std::runtime_error ("Unknown object type"); + Throw ("Unknown object type"); } } @@ -167,7 +168,7 @@ STVar::STVar (SerializedTypeID id, SField const& name) case STI_OBJECT: construct(name); return; case STI_ARRAY: construct(name); return; default: - throw std::runtime_error ("Unknown object type"); + Throw ("Unknown object type"); } } diff --git a/src/ripple/protocol/impl/Serializer.cpp b/src/ripple/protocol/impl/Serializer.cpp index 959706b8a..a55529fbb 100644 --- a/src/ripple/protocol/impl/Serializer.cpp +++ b/src/ripple/protocol/impl/Serializer.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -283,7 +284,7 @@ bool Serializer::getVL (Blob& objectVL, int offset, int& length) const } else return false; } - catch (...) + catch (std::exception const&) { return false; } @@ -324,7 +325,7 @@ bool Serializer::getVLLength (int& length, int offset) const } else return false; } - catch (...) + catch (std::exception const&) { return false; } @@ -357,14 +358,14 @@ int Serializer::addEncoded (int length) bytes[2] = static_cast (length & 0xff); numBytes = 3; } - else throw std::overflow_error ("lenlen"); + else Throw ("lenlen"); return addRaw (&bytes[0], numBytes); } int Serializer::encodeLengthLength (int length) { - if (length < 0) throw std::overflow_error ("len<0"); + if (length < 0) Throw ("len<0"); if (length <= 192) return 1; @@ -372,12 +373,13 @@ int Serializer::encodeLengthLength (int length) if (length <= 918744) return 3; - throw std::overflow_error ("len>918744"); + Throw ("len>918744"); + return 0; // Silence compiler warning. } int Serializer::decodeLengthLength (int b1) { - if (b1 < 0) throw std::overflow_error ("b1<0"); + if (b1 < 0) Throw ("b1<0"); if (b1 <= 192) return 1; @@ -385,32 +387,33 @@ int Serializer::decodeLengthLength (int b1) if (b1 <= 254) return 3; - throw std::overflow_error ("b1>254"); + Throw ("b1>254"); + return 0; // Silence compiler warning. } int Serializer::decodeVLLength (int b1) { - if (b1 < 0) throw std::overflow_error ("b1<0"); + if (b1 < 0) Throw ("b1<0"); - if (b1 > 254) throw std::overflow_error ("b1>254"); + if (b1 > 254) Throw ("b1>254"); return b1; } int Serializer::decodeVLLength (int b1, int b2) { - if (b1 < 193) throw std::overflow_error ("b1<193"); + if (b1 < 193) Throw ("b1<193"); - if (b1 > 240) throw std::overflow_error ("b1>240"); + if (b1 > 240) Throw ("b1>240"); return 193 + (b1 - 193) * 256 + b2; } int Serializer::decodeVLLength (int b1, int b2, int b3) { - if (b1 < 241) throw std::overflow_error ("b1<241"); + if (b1 < 241) Throw ("b1<241"); - if (b1 > 254) throw std::overflow_error ("b1>254"); + if (b1 > 254) Throw ("b1>254"); return 12481 + (b1 - 241) * 65536 + b2 * 256 + b3; } @@ -448,7 +451,7 @@ unsigned char SerialIter::get8() { if (remain_ < 1) - throw std::runtime_error( + Throw ( "invalid SerialIter get8"); unsigned char t = *p_; ++p_; @@ -461,7 +464,7 @@ std::uint16_t SerialIter::get16() { if (remain_ < 2) - throw std::runtime_error( + Throw ( "invalid SerialIter get16"); auto t = p_; p_ += 2; @@ -476,7 +479,7 @@ std::uint32_t SerialIter::get32() { if (remain_ < 4) - throw std::runtime_error( + Throw ( "invalid SerialIter get32"); auto t = p_; p_ += 4; @@ -493,7 +496,7 @@ std::uint64_t SerialIter::get64 () { if (remain_ < 8) - throw std::runtime_error( + Throw ( "invalid SerialIter get64"); auto t = p_; p_ += 8; @@ -522,7 +525,7 @@ SerialIter::getFieldID (int& type, int& name) // uncommon type type = get8(); if (type == 0 || type < 16) - throw std::runtime_error( + Throw ( "gFID: uncommon type out of range " + std::to_string(type)); } @@ -532,7 +535,7 @@ SerialIter::getFieldID (int& type, int& name) // uncommon name name = get8(); if (name == 0 || name < 16) - throw std::runtime_error( + Throw ( "gFID: uncommon name out of range " + std::to_string(name)); } @@ -545,7 +548,7 @@ T SerialIter::getRawHelper (int size) static_assert(std::is_same::value || std::is_same::value, ""); if (remain_ < size) - throw std::runtime_error( + Throw ( "invalid SerialIter getRaw"); T result (size); memcpy(result.data (), p_, size); @@ -590,7 +593,7 @@ Slice SerialIter::getSlice (std::size_t bytes) { if (bytes > remain_) - throw std::runtime_error( + Throw ( "invalid SerialIter getSlice"); Slice s(p_, bytes); p_ += bytes; diff --git a/src/ripple/protocol/tests/InnerObjectFormats.test.cpp b/src/ripple/protocol/tests/InnerObjectFormats.test.cpp index e134775d0..cf3a1bdaf 100755 --- a/src/ripple/protocol/tests/InnerObjectFormats.test.cpp +++ b/src/ripple/protocol/tests/InnerObjectFormats.test.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include // RPC::containsError #include // Json::Reader @@ -180,7 +181,7 @@ public: Json::Reader ().parse (test.txt, req); if (RPC::contains_error (req)) { - throw std::runtime_error ( + Throw ( "Internal InnerObjectFormatsParsedJSON error. Bad JSON."); } STParsedJSONObject parsed ("request", req); diff --git a/src/ripple/protocol/tests/STAmount.test.cpp b/src/ripple/protocol/tests/STAmount.test.cpp index 866d5f69a..63a05d0cd 100644 --- a/src/ripple/protocol/tests/STAmount.test.cpp +++ b/src/ripple/protocol/tests/STAmount.test.cpp @@ -593,7 +593,7 @@ public: { pass (); } - catch (...) + catch (std::exception const&) { fail ("wrong exception"); } @@ -625,7 +625,7 @@ public: { pass (); } - catch (...) + catch (std::exception const&) { fail ("wrong exception"); } diff --git a/src/ripple/protocol/tests/STTx.test.cpp b/src/ripple/protocol/tests/STTx.test.cpp index 516de5268..129830d13 100644 --- a/src/ripple/protocol/tests/STTx.test.cpp +++ b/src/ripple/protocol/tests/STTx.test.cpp @@ -152,7 +152,7 @@ public: STTx copy (sit); serialized = true; } - catch (...) + catch (std::exception const&) { ; // If it threw then serialization failed. } diff --git a/src/ripple/rpc/Status.h b/src/ripple/rpc/Status.h index 94df3eb88..23b83a7be 100644 --- a/src/ripple/rpc/Status.h +++ b/src/ripple/rpc/Status.h @@ -35,7 +35,7 @@ namespace RPC { A Status can also be used to fill a Json::Value with a JSON-RPC 2.0 error response: see http://www.jsonrpc.org/specification#error_object */ -struct Status +struct Status : public std::exception { public: enum class Type {none, TER, error_code_i}; diff --git a/src/ripple/rpc/handlers/AccountTx.cpp b/src/ripple/rpc/handlers/AccountTx.cpp index 099c31ea5..2a912d27c 100644 --- a/src/ripple/rpc/handlers/AccountTx.cpp +++ b/src/ripple/rpc/handlers/AccountTx.cpp @@ -186,7 +186,7 @@ Json::Value doAccountTx (RPC::Context& context) return ret; #ifndef BEAST_DEBUG } - catch (...) + catch (std::exception const&) { return rpcError (rpcINTERNAL); } diff --git a/src/ripple/rpc/handlers/AccountTxOld.cpp b/src/ripple/rpc/handlers/AccountTxOld.cpp index eece8f9f7..9afed5fa6 100644 --- a/src/ripple/rpc/handlers/AccountTxOld.cpp +++ b/src/ripple/rpc/handlers/AccountTxOld.cpp @@ -215,7 +215,7 @@ Json::Value doAccountTxOld (RPC::Context& context) return ret; #ifndef BEAST_DEBUG } - catch (...) + catch (std::exception const&) { return rpcError (rpcINTERNAL); } diff --git a/src/ripple/rpc/handlers/Random.cpp b/src/ripple/rpc/handlers/Random.cpp index 8df67b511..e57e84d04 100644 --- a/src/ripple/rpc/handlers/Random.cpp +++ b/src/ripple/rpc/handlers/Random.cpp @@ -48,7 +48,7 @@ Json::Value doRandom (RPC::Context& context) jvResult[jss::random] = to_string (rand); return jvResult; } - catch (...) + catch (std::exception const&) { return rpcError (rpcINTERNAL); } diff --git a/src/ripple/rpc/impl/RPCHandler.cpp b/src/ripple/rpc/impl/RPCHandler.cpp index 90574deb9..2b19dce87 100644 --- a/src/ripple/rpc/impl/RPCHandler.cpp +++ b/src/ripple/rpc/impl/RPCHandler.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -266,7 +267,7 @@ void executeRPC ( { // Can't ever get here. assert (false); - throw std::logic_error ("RPC handler with no method"); + Throw ("RPC handler with no method"); } } diff --git a/src/ripple/rpc/tests/JSONRPC.test.cpp b/src/ripple/rpc/tests/JSONRPC.test.cpp index b4d9d494c..52d22e236 100644 --- a/src/ripple/rpc/tests/JSONRPC.test.cpp +++ b/src/ripple/rpc/tests/JSONRPC.test.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -1699,7 +1700,7 @@ public: Json::Value req; Json::Reader ().parse (txnTest.json, req); if (RPC::contains_error (req)) - throw std::runtime_error ( + Throw ( "Internal JSONRPC_test error. Bad test JSON."); static Role const testedRoles[] = diff --git a/src/ripple/rpc/tests/Status.test.cpp b/src/ripple/rpc/tests/Status.test.cpp index afb0f5ffb..148f7560f 100644 --- a/src/ripple/rpc/tests/Status.test.cpp +++ b/src/ripple/rpc/tests/Status.test.cpp @@ -19,6 +19,7 @@ #include #include +#include #include namespace ripple { @@ -183,7 +184,7 @@ private: testcase ("throw"); try { - throw Status (temBAD_PATH, {"path=sdcdfd"}); + Throw (Status(temBAD_PATH, { "path=sdcdfd" })); } catch (Status const& s) { @@ -192,7 +193,7 @@ private: expect (msgs.size () == 1, "Wrong number of messages"); expect (msgs[0] == "path=sdcdfd", msgs[0]); } - catch (...) + catch (std::exception const&) { expect (false, "Didn't catch a Status"); } diff --git a/src/ripple/server/impl/Door.cpp b/src/ripple/server/impl/Door.cpp index d365f12cb..ed0a83d6a 100644 --- a/src/ripple/server/impl/Door.cpp +++ b/src/ripple/server/impl/Door.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -180,8 +181,7 @@ Door::Door (boost::asio::io_service& io_service, { if (server_.journal().error) server_.journal().error << "Open port '" << port.name << "' failed:" << ec.message(); - throw std::exception(); - return; + Throw (); } acceptor_.set_option( @@ -190,8 +190,7 @@ Door::Door (boost::asio::io_service& io_service, { if (server_.journal().error) server_.journal().error << "Option for port '" << port.name << "' failed:" << ec.message(); - throw std::exception(); - return; + Throw (); } acceptor_.bind(local_address, ec); @@ -199,8 +198,7 @@ Door::Door (boost::asio::io_service& io_service, { if (server_.journal().error) server_.journal().error << "Bind port '" << port.name << "' failed:" << ec.message(); - throw std::exception(); - return; + Throw (); } acceptor_.listen(boost::asio::socket_base::max_connections, ec); @@ -208,8 +206,7 @@ Door::Door (boost::asio::io_service& io_service, { if (server_.journal().error) server_.journal().error << "Listen on port '" << port.name << "' failed:" << ec.message(); - throw std::exception(); - return; + Throw (); } if (server_.journal().info) server_.journal().info << diff --git a/src/ripple/server/impl/ServerHandlerImp.cpp b/src/ripple/server/impl/ServerHandlerImp.cpp index f3f3cd531..bb8f7a8d6 100644 --- a/src/ripple/server/impl/ServerHandlerImp.cpp +++ b/src/ripple/server/impl/ServerHandlerImp.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -514,11 +515,11 @@ parse_Port (ParsedPort& port, Section const& section, std::ostream& log) { port.ip = boost::asio::ip::address::from_string(result.first); } - catch(...) + catch (std::exception const&) { log << "Invalid value '" << result.first << "' for key 'ip' in [" << section.name() << "]\n"; - throw std::exception(); + Throw(); } } } @@ -532,13 +533,13 @@ parse_Port (ParsedPort& port, Section const& section, std::ostream& log) { log << "Value '" << result.first << "' for key 'port' is out of range\n"; - throw std::exception(); + Throw (); } if (ul == 0) { log << "Value '0' for key 'port' is invalid\n"; - throw std::exception(); + Throw (); } port.port = static_cast(ul); } @@ -570,7 +571,7 @@ parse_Port (ParsedPort& port, Section const& section, std::ostream& log) { log << "Invalid value '" << ip << "' for key 'admin' in [" << section.name () << "]\n"; - throw std::exception (); + Throw (); } if (is_unspecified (addr.first)) @@ -580,7 +581,7 @@ parse_Port (ParsedPort& port, Section const& section, std::ostream& log) { log << "IP specified along with 0.0.0.0 '" << ip << "' for key 'admin' in [" << section.name () << "]\n"; - throw std::exception (); + Throw (); } port.admin_ip->emplace_back (addr.first.address ()); @@ -606,19 +607,19 @@ to_Port(ParsedPort const& parsed, std::ostream& log) if (! parsed.ip) { log << "Missing 'ip' in [" << p.name << "]\n"; - throw std::exception(); + Throw (); } p.ip = *parsed.ip; if (! parsed.port) { log << "Missing 'port' in [" << p.name << "]\n"; - throw std::exception(); + Throw (); } else if (*parsed.port == 0) { log << "Port " << *parsed.port << "in [" << p.name << "] is invalid\n"; - throw std::exception(); + Throw (); } p.port = *parsed.port; if (parsed.admin_ip) @@ -627,7 +628,7 @@ to_Port(ParsedPort const& parsed, std::ostream& log) if (parsed.protocol.empty()) { log << "Missing 'protocol' in [" << p.name << "]\n"; - throw std::exception(); + Throw (); } p.protocol = parsed.protocol; if (p.websockets() && @@ -636,7 +637,7 @@ to_Port(ParsedPort const& parsed, std::ostream& log) parsed.protocol.count("https") > 0)) { log << "Invalid protocol combination in [" << p.name << "]\n"; - throw std::exception(); + Throw (); } p.user = parsed.user; @@ -659,7 +660,7 @@ parse_Ports (BasicConfig const& config, std::ostream& log) { log << "Required section [server] is missing\n"; - throw std::exception(); + Throw (); } ParsedPort common; @@ -673,7 +674,7 @@ parse_Ports (BasicConfig const& config, std::ostream& log) { log << "Missing section: [" << name << "]\n"; - throw std::exception(); + Throw (); } ParsedPort parsed = common; parsed.name = name; @@ -688,7 +689,7 @@ parse_Ports (BasicConfig const& config, std::ostream& log) if (count > 1) { log << "Error: More than one peer protocol configured in [server]\n"; - throw std::exception(); + Throw (); } if (count == 0) log << "Warning: No peer protocol configured\n"; diff --git a/src/ripple/server/impl/ServerImpl.cpp b/src/ripple/server/impl/ServerImpl.cpp index 7908d4ca5..61ca7782a 100644 --- a/src/ripple/server/impl/ServerImpl.cpp +++ b/src/ripple/server/impl/ServerImpl.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include #include @@ -60,7 +61,7 @@ void ServerImpl::ports (std::vector const& ports) { if (closed()) - throw std::logic_error("ports() on closed HTTP::Server"); + Throw ("ports() on closed HTTP::Server"); for(auto const& _ : ports) if (! _.websockets()) std::make_shared( diff --git a/src/ripple/shamap/impl/SHAMap.cpp b/src/ripple/shamap/impl/SHAMap.cpp index 91c435795..50edea206 100644 --- a/src/ripple/shamap/impl/SHAMap.cpp +++ b/src/ripple/shamap/impl/SHAMap.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include #include @@ -180,7 +181,7 @@ SHAMap::fetchNodeFromDB (SHAMapHash const& hash) const if (node) canonicalize (hash, node); } - catch (...) + catch (std::exception const&) { if (journal_.warning) journal_.warning << "Invalid DB node " << hash; @@ -261,7 +262,7 @@ std::shared_ptr SHAMap::fetchNode (SHAMapHash const& hash) c auto node = fetchNodeNT (hash); if (!node) - throw SHAMapMissingNode (type_, hash); + Throw (type_, hash); return node; } @@ -271,7 +272,7 @@ SHAMapAbstractNode* SHAMap::descendThrow (SHAMapInnerNode* parent, int branch) c SHAMapAbstractNode* ret = descend (parent, branch); if (! ret && ! parent->isEmptyBranch (branch)) - throw SHAMapMissingNode (type_, parent->getChildHash (branch)); + Throw (type_, parent->getChildHash (branch)); return ret; } @@ -282,7 +283,7 @@ SHAMap::descendThrow (std::shared_ptr const& parent, int branch std::shared_ptr ret = descend (parent, branch); if (! ret && ! parent->isEmptyBranch (branch)) - throw SHAMapMissingNode (type_, parent->getChildHash (branch)); + Throw (type_, parent->getChildHash (branch)); return ret; } @@ -530,7 +531,7 @@ SHAMap::peekNextItem(uint256 const& id, NodeStack& stack) const stack.push({node, nodeID}); auto leaf = firstBelow(node, stack); if (!leaf) - throw SHAMapMissingNode(type_, id); + Throw (type_, id); assert(leaf->isLeaf()); return leaf->peekItem().get(); } @@ -621,7 +622,7 @@ SHAMap::upper_bound(uint256 const& id) const stack.push({node, nodeID}); auto leaf = firstBelow(node, stack); if (!leaf) - throw SHAMapMissingNode(type_, id); + Throw (type_, id); return const_iterator(this, leaf->peekItem().get(), std::move(stack)); } @@ -647,7 +648,7 @@ bool SHAMap::delItem (uint256 const& id) auto stack = getStack (id, true); if (stack.empty ()) - throw SHAMapMissingNode(type_, id); + Throw (type_, id); auto leaf = std::dynamic_pointer_cast(stack.top ().first); stack.pop (); @@ -735,7 +736,7 @@ SHAMap::addGiveItem (std::shared_ptr const& item, auto stack = getStack (tag, true); if (stack.empty ()) - throw SHAMapMissingNode(type_, tag); + Throw (type_, tag); auto node = stack.top ().first; auto nodeID = stack.top ().second; @@ -832,7 +833,7 @@ SHAMap::updateGiveItem (std::shared_ptr const& item, auto stack = getStack (tag, true); if (stack.empty ()) - throw SHAMapMissingNode(type_, tag); + Throw (type_, tag); auto node = std::dynamic_pointer_cast(stack.top().first); auto nodeID = stack.top ().second; diff --git a/src/ripple/shamap/impl/SHAMapDelta.cpp b/src/ripple/shamap/impl/SHAMapDelta.cpp index 8a5cfe20f..309024340 100644 --- a/src/ripple/shamap/impl/SHAMapDelta.cpp +++ b/src/ripple/shamap/impl/SHAMapDelta.cpp @@ -18,6 +18,7 @@ //============================================================================== #include +#include #include namespace ripple { @@ -139,7 +140,7 @@ SHAMap::compare (SHAMap const& otherMap, if (!ourNode || !otherNode) { assert (false); - throw SHAMapMissingNode (type_, uint256 ()); + Throw (type_, uint256 ()); } if (ourNode->isLeaf () && otherNode->isLeaf ()) diff --git a/src/ripple/shamap/impl/SHAMapTreeNode.cpp b/src/ripple/shamap/impl/SHAMapTreeNode.cpp index bd8200205..7e48190d5 100644 --- a/src/ripple/shamap/impl/SHAMapTreeNode.cpp +++ b/src/ripple/shamap/impl/SHAMapTreeNode.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -103,13 +104,13 @@ SHAMapAbstractNode::make(Blob const& rawNode, std::uint32_t seq, SHANodeFormat f { // account state if (len < (256 / 8)) - throw std::runtime_error ("short AS node"); + Throw ("short AS node"); uint256 u; s.get256 (u, len - (256 / 8)); s.chop (256 / 8); - if (u.isZero ()) throw std::runtime_error ("invalid AS node"); + if (u.isZero ()) Throw ("invalid AS node"); auto item = std::make_shared (u, s.peekData ()); if (hashValid) @@ -120,7 +121,7 @@ SHAMapAbstractNode::make(Blob const& rawNode, std::uint32_t seq, SHANodeFormat f { // full inner if (len != 512) - throw std::runtime_error ("invalid FI node"); + Throw ("invalid FI node"); auto ret = std::make_shared(seq); for (int i = 0; i < 16; ++i) @@ -143,10 +144,10 @@ SHAMapAbstractNode::make(Blob const& rawNode, std::uint32_t seq, SHANodeFormat f for (int i = 0; i < (len / 33); ++i) { int pos; - if (!s.get8 (pos, 32 + (i * 33))) - throw std::runtime_error ("short CI node"); + if (! s.get8 (pos, 32 + (i * 33))) + Throw ("short CI node"); if ((pos < 0) || (pos >= 16)) - throw std::runtime_error ("invalid CI node"); + Throw ("invalid CI node"); s.get256 (ret->mHashes[pos].as_uint256(), i * 33); if (ret->mHashes[pos].isNonZero ()) ret->mIsBranch |= (1 << pos); @@ -161,14 +162,14 @@ SHAMapAbstractNode::make(Blob const& rawNode, std::uint32_t seq, SHANodeFormat f { // transaction with metadata if (len < (256 / 8)) - throw std::runtime_error ("short TM node"); + Throw ("short TM node"); uint256 u; s.get256 (u, len - (256 / 8)); s.chop (256 / 8); if (u.isZero ()) - throw std::runtime_error ("invalid TM node"); + Throw ("invalid TM node"); auto item = std::make_shared (u, s.peekData ()); if (hashValid) @@ -182,7 +183,7 @@ SHAMapAbstractNode::make(Blob const& rawNode, std::uint32_t seq, SHANodeFormat f if (rawNode.size () < 4) { JLOG (j.info) << "size < 4"; - throw std::runtime_error ("invalid P node"); + Throw ("invalid P node"); } std::uint32_t prefix = rawNode[0]; @@ -206,7 +207,7 @@ SHAMapAbstractNode::make(Blob const& rawNode, std::uint32_t seq, SHANodeFormat f else if (prefix == HashPrefix::leafNode) { if (s.getLength () < 32) - throw std::runtime_error ("short PLN node"); + Throw ("short PLN node"); uint256 u; s.get256 (u, s.getLength () - 32); @@ -215,7 +216,7 @@ SHAMapAbstractNode::make(Blob const& rawNode, std::uint32_t seq, SHANodeFormat f if (u.isZero ()) { JLOG (j.info) << "invalid PLN node"; - throw std::runtime_error ("invalid PLN node"); + Throw ("invalid PLN node"); } auto item = std::make_shared (u, s.peekData ()); @@ -226,7 +227,7 @@ SHAMapAbstractNode::make(Blob const& rawNode, std::uint32_t seq, SHANodeFormat f else if (prefix == HashPrefix::innerNode) { if (s.getLength () != 512) - throw std::runtime_error ("invalid PIN node"); + Throw ("invalid PIN node"); auto ret = std::make_shared(seq); for (int i = 0; i < 16; ++i) { @@ -245,7 +246,7 @@ SHAMapAbstractNode::make(Blob const& rawNode, std::uint32_t seq, SHANodeFormat f { // transaction with metadata if (s.getLength () < 32) - throw std::runtime_error ("short TXN node"); + Throw ("short TXN node"); uint256 txID; s.get256 (txID, s.getLength () - 32); @@ -258,11 +259,12 @@ SHAMapAbstractNode::make(Blob const& rawNode, std::uint32_t seq, SHANodeFormat f else { JLOG (j.info) << "Unknown node prefix " << std::hex << prefix << std::dec; - throw std::runtime_error ("invalid node prefix"); + Throw ("invalid node prefix"); } } assert (false); - throw std::runtime_error ("Unknown format"); + Throw ("Unknown format"); + return{}; // Silence compiler warning. } bool @@ -330,7 +332,7 @@ SHAMapInnerNode::addRaw(Serializer& s, SHANodeFormat format) const assert ((format == snfPREFIX) || (format == snfWIRE) || (format == snfHASH)); if (mType == tnERROR) - throw std::runtime_error ("invalid I node type"); + Throw ("invalid I node type"); if (format == snfHASH) { @@ -380,7 +382,7 @@ SHAMapTreeNode::addRaw(Serializer& s, SHANodeFormat format) const assert ((format == snfPREFIX) || (format == snfWIRE) || (format == snfHASH)); if (mType == tnERROR) - throw std::runtime_error ("invalid I node type"); + Throw ("invalid I node type"); if (format == snfHASH) { diff --git a/src/ripple/shamap/tests/FetchPack.test.cpp b/src/ripple/shamap/tests/FetchPack.test.cpp index 2a074c3a3..8f6d9dfd0 100644 --- a/src/ripple/shamap/tests/FetchPack.test.cpp +++ b/src/ripple/shamap/tests/FetchPack.test.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -49,7 +50,7 @@ public: { void operator()(std::uint32_t refNum) const { - throw std::runtime_error("missing node"); + Throw ("missing node"); } }; @@ -153,7 +154,7 @@ public: // expect (t3->getHash () == t2->getHash (), "root hashes do not match"); // expect (t3->deepCompare (*t2), "failed compare"); // } -// catch (...) +// catch (std::exception const&) // { // fail ("unhandled exception"); // } diff --git a/src/ripple/shamap/tests/common.h b/src/ripple/shamap/tests/common.h index 56de81c88..8a98b3acc 100644 --- a/src/ripple/shamap/tests/common.h +++ b/src/ripple/shamap/tests/common.h @@ -21,6 +21,7 @@ #define RIPPLE_SHAMAP_TESTS_COMMON_H_INCLUDED #include +#include #include #include #include @@ -108,13 +109,13 @@ public: void missing_node (std::uint32_t refNum) override { - throw std::runtime_error("missing node"); + Throw ("missing node"); } void missing_node (uint256 const& refHash) override { - throw std::runtime_error("missing node"); + Throw ("missing node"); } }; diff --git a/src/ripple/test/jtx/amount.h b/src/ripple/test/jtx/amount.h index 8681dfe07..807dc415d 100644 --- a/src/ripple/test/jtx/amount.h +++ b/src/ripple/test/jtx/amount.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -197,14 +198,14 @@ struct XRP_t auto const d = std::uint64_t( std::round(v * c)); if (double(d) / c != v) - throw std::domain_error( + Throw ( "unrepresentable"); return { d }; } auto const d = std::int64_t( std::round(v * c)); if (double(d) / c != v) - throw std::domain_error( + Throw ( "unrepresentable"); return { d }; } diff --git a/src/ripple/test/jtx/fee.h b/src/ripple/test/jtx/fee.h index 1dcd63f46..5a6a09e36 100644 --- a/src/ripple/test/jtx/fee.h +++ b/src/ripple/test/jtx/fee.h @@ -23,6 +23,7 @@ #include #include #include +#include #include namespace ripple { @@ -53,7 +54,7 @@ public: : amount_(amount) { if (! isXRP(*amount_)) - throw std::runtime_error( + Throw ( "fee: not XRP"); } diff --git a/src/ripple/test/jtx/flags.h b/src/ripple/test/jtx/flags.h index 907e40b0c..2bf5b8e44 100644 --- a/src/ripple/test/jtx/flags.h +++ b/src/ripple/test/jtx/flags.h @@ -23,6 +23,7 @@ #include #include #include +#include namespace ripple { namespace test { @@ -72,7 +73,7 @@ private: case asfGlobalFreeze: mask_ |= lsfGlobalFreeze; break; case asfDefaultRipple: mask_ |= lsfDefaultRipple; break; default: - throw std::runtime_error( + Throw ( "unknown flag"); } } diff --git a/src/ripple/test/jtx/impl/Env.cpp b/src/ripple/test/jtx/impl/Env.cpp index 81bb39bec..a62f9b10b 100644 --- a/src/ripple/test/jtx/impl/Env.cpp +++ b/src/ripple/test/jtx/impl/Env.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -155,7 +156,7 @@ Env::lookup (AccountID const& id) const { auto const iter = map_.find(id); if (iter == map_.end()) - throw std::runtime_error( + Throw ( "Env::lookup:: unknown account ID"); return iter->second; } @@ -166,7 +167,7 @@ Env::lookup (std::string const& base58ID) const auto const account = parseBase58(base58ID); if (! account) - throw std::runtime_error( + Throw( "Env::lookup: invalid account ID"); return lookup(*account); } @@ -206,7 +207,7 @@ Env::seq (Account const& account) const { auto const sle = le(account); if (! sle) - throw std::runtime_error( + Throw ( "missing account root"); return sle->getFieldU32(sfSequence); } @@ -371,7 +372,7 @@ Env::autofill (JTx& jt) test.log << "parse failed:\n" << pretty(jv); - throw; + Throw(); } } @@ -390,14 +391,14 @@ Env::st (JTx const& jt) test.log << "Exception: parse_error\n" << pretty(jt.jv); - throw; + Throw(); } try { return sterilize(STTx{std::move(*obj)}); } - catch(...) + catch(std::exception const&) { } return nullptr; diff --git a/src/ripple/test/jtx/impl/jtx_json.cpp b/src/ripple/test/jtx/impl/jtx_json.cpp index 879a491cb..26ea0e33a 100644 --- a/src/ripple/test/jtx/impl/jtx_json.cpp +++ b/src/ripple/test/jtx/impl/jtx_json.cpp @@ -21,6 +21,7 @@ #include #include #include +#include namespace ripple { namespace test { @@ -29,7 +30,7 @@ namespace jtx { json::json(std::string const& s) { if (! Json::Reader().parse(s, jv_)) - throw parse_error("bad json"); + Throw ("bad json"); } diff --git a/src/ripple/test/jtx/impl/multisign.cpp b/src/ripple/test/jtx/impl/multisign.cpp index c713d8212..9e1e598e2 100644 --- a/src/ripple/test/jtx/impl/multisign.cpp +++ b/src/ripple/test/jtx/impl/multisign.cpp @@ -24,6 +24,7 @@ #include #include #include +#include namespace ripple { namespace test { @@ -88,7 +89,7 @@ msig::operator()(Env& env, JTx& jt) const catch(parse_error const&) { env.test.log << pretty(jt.jv); - throw; + Throw(); } auto& js = jt[sfSigners.getJsonName()]; js.resize(mySigners.size()); diff --git a/src/ripple/test/jtx/impl/rate.cpp b/src/ripple/test/jtx/impl/rate.cpp index 403ff5432..d931772ee 100644 --- a/src/ripple/test/jtx/impl/rate.cpp +++ b/src/ripple/test/jtx/impl/rate.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include namespace ripple { @@ -30,7 +31,7 @@ Json::Value rate (Account const& account, double multiplier) { if (multiplier > 4) - throw std::runtime_error( + Throw ( "rate multiplier out of range"); Json::Value jv; jv[jss::Account] = account.human(); diff --git a/src/ripple/test/jtx/impl/trust.cpp b/src/ripple/test/jtx/impl/trust.cpp index dc2305f5d..0f7c79548 100644 --- a/src/ripple/test/jtx/impl/trust.cpp +++ b/src/ripple/test/jtx/impl/trust.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include namespace ripple { @@ -31,7 +32,7 @@ trust (Account const& account, STAmount const& amount) { if (isXRP(amount)) - throw std::runtime_error( + Throw ( "trust() requires IOU"); Json::Value jv; jv[jss::Account] = account.human(); diff --git a/src/ripple/test/jtx/impl/utility.cpp b/src/ripple/test/jtx/impl/utility.cpp index cd397041e..e55af792e 100644 --- a/src/ripple/test/jtx/impl/utility.cpp +++ b/src/ripple/test/jtx/impl/utility.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include namespace ripple { @@ -36,7 +37,7 @@ parse (Json::Value const& jv) { STParsedJSONObject p("tx_json", jv); if (! p.object) - throw parse_error( + Throw ( rpcErrorString(p.error)); return std::move(*p.object); } @@ -77,12 +78,12 @@ fill_seq (Json::Value& jv, parseBase58( jv[jss::Account].asString()); if (! account) - throw parse_error( + Throw ( "unexpected invalid Account"); auto const ar = view.read( keylet::account(*account)); if (! ar) - throw parse_error( + Throw ( "unexpected missing account root"); jv[jss::Sequence] = ar->getFieldU32(sfSequence); diff --git a/src/ripple/unity/basics.cpp b/src/ripple/unity/basics.cpp index fa4da07fe..93098ed23 100644 --- a/src/ripple/unity/basics.cpp +++ b/src/ripple/unity/basics.cpp @@ -36,6 +36,7 @@ #include #include +#include #include #include #include diff --git a/src/ripple/unl/tests/qalloc.h b/src/ripple/unl/tests/qalloc.h index 85ddd1c7d..29efe0ec5 100644 --- a/src/ripple/unl/tests/qalloc.h +++ b/src/ripple/unl/tests/qalloc.h @@ -20,6 +20,7 @@ #ifndef RIPPLE_SIM_QALLOC_H_INCLUDED #define RIPPLE_SIM_QALLOC_H_INCLUDED +#include #include #include #include @@ -266,7 +267,7 @@ qalloc_impl<_>::allocate( block* const b = new(std::malloc(n)) block(n); if (! b) - throw std::bad_alloc(); + Throw (); used_ = b; // VFALCO This has to succeed return used_->allocate(bytes, align); @@ -313,7 +314,7 @@ qalloc_type::alloc (std::size_t n) { if (n > std::numeric_limits< std::size_t>::max() / sizeof(U)) - throw std::bad_alloc(); + Throw (); auto const bytes = n * sizeof(U); return static_cast( impl_->allocate(bytes, diff --git a/src/ripple/websocket/Handler.h b/src/ripple/websocket/Handler.h index fcdc0aa5a..7515e17c9 100644 --- a/src/ripple/websocket/Handler.h +++ b/src/ripple/websocket/Handler.h @@ -116,7 +116,7 @@ public: cpClient->send ( mpMessage->get_payload (), mpMessage->get_opcode ()); } - catch (...) + catch (std::exception const&) { WebSocket::closeTooSlowClient (*cpClient, crTooSlow); } @@ -133,7 +133,7 @@ public: cpClient->send (strMessage); } - catch (...) + catch (std::exception const&) { WebSocket::closeTooSlowClient (*cpClient, crTooSlow); } @@ -170,7 +170,7 @@ public: // cpClient->get_socket ().remote_endpoint ().to_string () ")"; } - catch (...) + catch (std::exception const&) { } } @@ -217,7 +217,7 @@ public: JLOG (j_.debug) << "Ws:: on_open(" << remoteEndpoint << ")"; } - catch (...) + catch (std::exception const&) { } } @@ -239,7 +239,7 @@ public: JLOG (j_.debug) << "Ws:: on_pong(" << cpClient->get_socket ().remote_endpoint() << ")"; } - catch (...) + catch (std::exception const&) { } ptr->onPong (data); @@ -273,7 +273,7 @@ public: cpClient->get_socket ().remote_endpoint() << ") not found"; } - catch (...) + catch (std::exception const&) { } return; @@ -291,7 +291,7 @@ public: "Ws:: " << reason << "(" << cpClient->get_socket ().remote_endpoint () << ") found"; } - catch (...) + catch (std::exception const&) { } @@ -334,7 +334,7 @@ public: cpClient->get_socket().remote_endpoint() << ") '" << mpMessage->get_payload () << "'"; } - catch (...) + catch (std::exception const&) { } } @@ -391,7 +391,7 @@ public: << cpClient->get_socket ().remote_endpoint () << ") '" << mpMessage->get_payload () << "'"; } - catch (...) + catch (std::exception const&) { } diff --git a/src/ripple/websocket/WebSocket02.cpp b/src/ripple/websocket/WebSocket02.cpp index c197d39b5..f67b77a3b 100644 --- a/src/ripple/websocket/WebSocket02.cpp +++ b/src/ripple/websocket/WebSocket02.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include // This file contains websocket::WebSocket02 implementations for the WebSocket @@ -122,7 +123,7 @@ void Server ::listen() } } } - throw e; + Throw (e); } }