Better unhandled exception handling:

Log thread name and exception type on unhandled exceptions and use a
terminate handler to get a stack trace that includes the function that
thows the exception.
This commit is contained in:
seelabs
2016-07-05 16:12:15 -04:00
parent c9d8fa9e96
commit 6f3a35e8be
11 changed files with 125 additions and 271 deletions

View File

@@ -77,15 +77,12 @@ bool Job::shouldCancel () const
void Job::doJob ()
{
threadEntry (this, &Job::doJobImpl, "Job::doJob()",
[this] ()
{
std::stringstream ss;
ss << "Job name: " << this->mName
<< "; Job type: " << this->mType
<< "; Job info: " << this->mJob.target_type().name();
return ss.str();
});
std::stringstream ss;
ss << "Job::doJob(); Job name: "
<< mName << "; Job type: " << mType
<< "; Job info: " << mJob.target_type ().name ();
threadEntry (this, &Job::doJobImpl, ss.str());
}
void Job::rename (std::string const& newName)

View File

@@ -0,0 +1,71 @@
//------------------------------------------------------------------------------
/*
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 <BeastConfig.h>
#include <ripple/core/ThreadEntry.h>
#include <ripple/basics/Log.h>
#include <boost/coroutine/exceptions.hpp>
#include <exception>
#include <iostream>
namespace ripple {
#ifndef NO_LOG_UNHANDLED_EXCEPTIONS
namespace detail {
thread_local
std::string threadName;
void setThreadName(std::string name)
{
threadName = std::move(name);
}
}
void terminateHandler()
{
if (std::current_exception())
{
try
{
throw;
}
catch (const std::exception& e)
{
std::cerr << detail::threadName << ": " << e.what () << '\n';
JLOG(debugLog().fatal())
<< detail::threadName << ": " << e.what () << '\n';
}
catch (boost::coroutines::detail::forced_unwind const&)
{
std::cerr << detail::threadName << ": forced_unwind\n";
JLOG(debugLog().fatal())
<< detail::threadName << ": forced_unwind\n";
}
catch (...)
{
std::cerr << detail::threadName << ": unknown exception\n";
JLOG (debugLog ().fatal ())
<< detail::threadName << ": unknown exception\n";
}
}
}
#endif
}

View File

@@ -160,10 +160,7 @@ void Workers::Worker::run ()
{
// Call runImpl() and report if any exceptions escape runImpl.
threadEntry (this, &Workers::Worker::runImpl,
"Workers::Worker::run()", [this] ()
{
return "Thread: " + Thread::getThreadName();
});
"Workers::Worker::run(); Thread: " + Thread::getThreadName());
}
void Workers::Worker::runImpl ()