mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Add ripple::FatalErrorReporter
This commit is contained in:
55
modules/ripple_app/main/ripple_FatalErrorReporter.cpp
Normal file
55
modules/ripple_app/main/ripple_FatalErrorReporter.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
FatalErrorReporter::FatalErrorReporter ()
|
||||
{
|
||||
FatalError::setReporter (*this);
|
||||
}
|
||||
|
||||
FatalErrorReporter::~FatalErrorReporter ()
|
||||
{
|
||||
FatalError::resetReporter (*this);
|
||||
}
|
||||
|
||||
void FatalErrorReporter::onFatalError (
|
||||
char const* message,
|
||||
char const* stackBacktrace,
|
||||
char const* fileName,
|
||||
int lineNumber)
|
||||
{
|
||||
String s;
|
||||
|
||||
s << "Message = '" << message << "'" << newLine;
|
||||
s << "File = '" << fileName << "' Line " << String (lineNumber) << newLine;
|
||||
s << "Stack Trace:" << newLine;
|
||||
s << stackBacktrace;
|
||||
|
||||
Log::out() << s;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class FatalErrorReporterTests : public UnitTest
|
||||
{
|
||||
public:
|
||||
FatalErrorReporterTests () : UnitTest ("FatalErrorReporter", "ripple", runManual)
|
||||
{
|
||||
}
|
||||
|
||||
void runTest ()
|
||||
{
|
||||
beginTestCase ("report");
|
||||
|
||||
FatalErrorReporter reporter;
|
||||
|
||||
// We don't really expect the program to run after this
|
||||
// but the unit test is here so you can manually test it.
|
||||
|
||||
FatalError ("unit test", __FILE__, __LINE__);
|
||||
}
|
||||
};
|
||||
|
||||
static FatalErrorReporterTests fatalErrorReporterTests;
|
||||
33
modules/ripple_app/main/ripple_FatalErrorReporter.h
Normal file
33
modules/ripple_app/main/ripple_FatalErrorReporter.h
Normal file
@@ -0,0 +1,33 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
Copyright (c) 2011-2013, OpenCoin, Inc.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef RIPPLE_SCOPEDFATALERRORREPORTER_H_INCLUDED
|
||||
#define RIPPLE_SCOPEDFATALERRORREPORTER_H_INCLUDED
|
||||
|
||||
/** FatalError reporter.
|
||||
|
||||
This writes the details to standard error and the log. The reporter is
|
||||
installed for the lifetime of the object so typically you would put this
|
||||
at the top of main().
|
||||
|
||||
An alternative is to make it a global variable but for this to cover all
|
||||
possible cases, there can be no other global variables with non trivial
|
||||
constructors that can report a fatal error. Also, the Log would need
|
||||
to be guaranteed to be set up for this handler to work.
|
||||
*/
|
||||
class FatalErrorReporter : public FatalError::Reporter
|
||||
{
|
||||
public:
|
||||
FatalErrorReporter ();
|
||||
~FatalErrorReporter ();
|
||||
|
||||
void onFatalError (char const* message,
|
||||
char const* stackBacktrace,
|
||||
char const* fileName,
|
||||
int lineNumber);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -226,6 +226,8 @@ static int runUnitTests (String const& whichTests, String const& format)
|
||||
|
||||
int rippleMain (int argc, char** argv)
|
||||
{
|
||||
FatalErrorReporter reporter;
|
||||
|
||||
//
|
||||
// These debug heap calls do nothing in release or non Visual Studio builds.
|
||||
//
|
||||
|
||||
@@ -376,6 +376,8 @@ static DH* handleTmpDh (SSL* ssl, int is_export, int iKeyLength)
|
||||
#include "ledger/ripple_AcceptedLedger.cpp"
|
||||
#include "consensus/ripple_DisputedTx.cpp"
|
||||
#include "misc/ripple_HashRouter.cpp"
|
||||
#include "main/ripple_FatalErrorReporter.h" // private
|
||||
#include "main/ripple_FatalErrorReporter.cpp"
|
||||
#include "main/ripple_Main.cpp"
|
||||
#include "misc/ripple_Offer.cpp"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user