mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Improve exception handling:
* Self-document the code by renaming Throw to Rethrow. * Write a message to the debug log when we throw or rethrow an exception.
This commit is contained in:
@@ -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 <SHAMapMissingNode> missingNodes1;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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<E*, std::exception*>::value,
|
||||
"Exception must derive from std::exception.");
|
||||
throw E(std::forward<Args>(args)...);
|
||||
|
||||
E e(std::forward<Args>(args)...);
|
||||
LogThrow (std::string("Throwing exception: ") + e.what());
|
||||
throw e;
|
||||
}
|
||||
|
||||
/** Called when faulty logic causes a broken invariant. */
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <BeastConfig.h>
|
||||
#include <ripple/basics/contract.h>
|
||||
#include <ripple/basics/Log.h>
|
||||
#include <cstdlib>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
|
||||
try
|
||||
{
|
||||
Throw();
|
||||
Rethrow();
|
||||
}
|
||||
catch (std::runtime_error const& e)
|
||||
{
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user