diff --git a/src/ripple/app/ledger/Ledger.cpp b/src/ripple/app/ledger/Ledger.cpp index 4383cbee6b..707bc452c9 100644 --- a/src/ripple/app/ledger/Ledger.cpp +++ b/src/ripple/app/ledger/Ledger.cpp @@ -603,7 +603,7 @@ Ledger::setup (Config const& config) } catch (std::exception const&) { - Throw(); + Rethrow(); } try @@ -616,7 +616,7 @@ Ledger::setup (Config const& config) } catch (std::exception const&) { - Throw(); + Rethrow(); } return ret; @@ -639,7 +639,6 @@ Ledger::peek (Keylet const& k) const } //------------------------------------------------------------------------------ - bool Ledger::walkLedger (beast::Journal j) const { std::vector missingNodes1; diff --git a/src/ripple/app/ledger/impl/LedgerConsensusImp.cpp b/src/ripple/app/ledger/impl/LedgerConsensusImp.cpp index 81324d166f..51982f1ab2 100644 --- a/src/ripple/app/ledger/impl/LedgerConsensusImp.cpp +++ b/src/ripple/app/ledger/impl/LedgerConsensusImp.cpp @@ -487,7 +487,7 @@ void LedgerConsensusImp::mapComplete ( leaveConsensus(); JLOG (j_.error()) << "Missing node processing complete map " << mn; - Throw(); + Rethrow(); } } @@ -693,7 +693,7 @@ void LedgerConsensusImp::timerEntry () leaveConsensus (); JLOG (j_.error()) << "Missing node during consensus process " << mn; - Throw(); + Rethrow(); } } diff --git a/src/ripple/app/paths/RippleCalc.cpp b/src/ripple/app/paths/RippleCalc.cpp index 5db8df17c0..6c5c930d1a 100644 --- a/src/ripple/app/paths/RippleCalc.cpp +++ b/src/ripple/app/paths/RippleCalc.cpp @@ -143,7 +143,7 @@ RippleCalc::Output RippleCalc::rippleCalculate ( { JLOG (j.trace()) << "Exception from flow" << e.what (); if (!useFlowV1Output) - Throw(); + Rethrow(); } if (j.debug()) @@ -151,12 +151,12 @@ RippleCalc::Output RippleCalc::rippleCalculate ( auto logResult = [&] (std::string const& algoName, Output const& result) { j.debug() << "RippleCalc Result> " << - " actualIn: " << result.actualAmountIn << - ", actualOut: " << result.actualAmountOut << - ", result: " << result.result () << - ", dstAmtReq: " << saDstAmountReq << - ", sendMax: " << saMaxAmountReq << - ", algo: " << algoName; + " actualIn: " << result.actualAmountIn << + ", actualOut: " << result.actualAmountOut << + ", result: " << result.result () << + ", dstAmtReq: " << saDstAmountReq << + ", sendMax: " << saMaxAmountReq << + ", algo: " << algoName; }; if (callFlowV1) { diff --git a/src/ripple/basics/contract.h b/src/ripple/basics/contract.h index 3c31480d0c..386aff65bf 100644 --- a/src/ripple/basics/contract.h +++ b/src/ripple/basics/contract.h @@ -33,11 +33,22 @@ namespace ripple { preconditions, postconditions, and invariants. */ +/** Generates and logs a call stack */ +void +LogThrow (std::string const& title); + +/** Rethrow the exception currently being handled. + + When called from within a catch block, it will pass + control to the next matching exception handler, if any. + Otherwise, std::terminate will be called. +*/ [[noreturn]] inline void -Throw () +Rethrow () { + LogThrow ("Re-throwing exception"); throw; } @@ -49,7 +60,10 @@ Throw (Args&&... args) { static_assert (std::is_convertible::value, "Exception must derive from std::exception."); - throw E(std::forward(args)...); + + E e(std::forward(args)...); + LogThrow (std::string("Throwing exception: ") + e.what()); + throw e; } /** Called when faulty logic causes a broken invariant. */ diff --git a/src/ripple/basics/impl/contract.cpp b/src/ripple/basics/impl/contract.cpp index 2e2f451063..20c1aaba39 100644 --- a/src/ripple/basics/impl/contract.cpp +++ b/src/ripple/basics/impl/contract.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -39,10 +40,17 @@ accessViolation() noexcept } // detail +void +LogThrow (std::string const& title) +{ + JLOG(debugLog()) << title; +} + [[noreturn]] void LogicError (std::string const& s) noexcept { + JLOG(debugLog()) << s; std::cerr << "Logic error: " << s << std::endl; detail::accessViolation(); } diff --git a/src/ripple/basics/tests/contract.test.cpp b/src/ripple/basics/tests/contract.test.cpp index 8aac1ad142..e8f77fb200 100644 --- a/src/ripple/basics/tests/contract.test.cpp +++ b/src/ripple/basics/tests/contract.test.cpp @@ -39,7 +39,7 @@ public: try { - Throw(); + Rethrow(); } catch (std::runtime_error const& e) { diff --git a/src/ripple/nodestore/tests/Timing.test.cpp b/src/ripple/nodestore/tests/Timing.test.cpp index 8f0ac39a82..d70a488bbd 100644 --- a/src/ripple/nodestore/tests/Timing.test.cpp +++ b/src/ripple/nodestore/tests/Timing.test.cpp @@ -317,7 +317,7 @@ public: #if NODESTORE_TIMING_DO_VERIFY backend->verify(); #endif - Throw(); + Rethrow(); } backend->close(); } @@ -378,7 +378,7 @@ public: #if NODESTORE_TIMING_DO_VERIFY backend->verify(); #endif - Throw(); + Rethrow(); } backend->close(); } @@ -441,7 +441,7 @@ public: #if NODESTORE_TIMING_DO_VERIFY backend->verify(); #endif - Throw(); + Rethrow(); } backend->close(); } @@ -519,7 +519,7 @@ public: #if NODESTORE_TIMING_DO_VERIFY backend->verify(); #endif - Throw(); + Rethrow(); } backend->close(); } @@ -631,7 +631,7 @@ public: #if NODESTORE_TIMING_DO_VERIFY backend->verify(); #endif - Throw(); + Rethrow(); } backend->close(); } diff --git a/src/ripple/server/impl/Port.cpp b/src/ripple/server/impl/Port.cpp index ab69bff98d..5752b82d5a 100644 --- a/src/ripple/server/impl/Port.cpp +++ b/src/ripple/server/impl/Port.cpp @@ -154,7 +154,7 @@ parse_Port (ParsedPort& port, Section const& section, std::ostream& log) { log << "Invalid value '" << result.first << "' for key 'ip' in [" << section.name() << "]\n"; - Throw(); + Rethrow(); } } } @@ -177,7 +177,7 @@ parse_Port (ParsedPort& port, Section const& section, std::ostream& log) log << "Invalid value '" << result.first << "' for key " << "'port' in [" << section.name() << "]\n"; - Throw(); + Rethrow(); } } } @@ -207,7 +207,7 @@ parse_Port (ParsedPort& port, Section const& section, std::ostream& log) log << "Invalid value '" << lim << "' for key " << "'limit' in [" << section.name() << "]\n"; - Throw(); + Rethrow(); } } } diff --git a/src/ripple/test/jtx/impl/Env.cpp b/src/ripple/test/jtx/impl/Env.cpp index bf675e693f..2f16e8aeff 100644 --- a/src/ripple/test/jtx/impl/Env.cpp +++ b/src/ripple/test/jtx/impl/Env.cpp @@ -450,7 +450,7 @@ Env::autofill (JTx& jt) test.log << "parse failed:\n" << pretty(jv); - Throw(); + Rethrow(); } } @@ -469,7 +469,7 @@ Env::st (JTx const& jt) test.log << "Exception: parse_error\n" << pretty(jt.jv); - Throw(); + Rethrow(); } try diff --git a/src/ripple/test/jtx/impl/multisign.cpp b/src/ripple/test/jtx/impl/multisign.cpp index 9e1e598e2d..4480bd97c3 100644 --- a/src/ripple/test/jtx/impl/multisign.cpp +++ b/src/ripple/test/jtx/impl/multisign.cpp @@ -89,7 +89,7 @@ msig::operator()(Env& env, JTx& jt) const catch(parse_error const&) { env.test.log << pretty(jt.jv); - Throw(); + Rethrow(); } auto& js = jt[sfSigners.getJsonName()]; js.resize(mySigners.size());