Fix ProtectedCall default handler

This commit is contained in:
Vinnie Falco
2013-08-20 08:10:13 -07:00
parent 52ff45549d
commit ac9c02f73b
2 changed files with 33 additions and 11 deletions

View File

@@ -277,9 +277,25 @@ bool CatchAny (Function <void (void)> f, bool returnFromException)
//------------------------------------------------------------------------------
void ProtectedCall::DefaultHandler::onException (ProtectedCall::Exception const&) const
class ProtectedCall::DefaultHandler : public Handler
{
}
public:
void onException (Exception const&) const
{
ScopedLockType lock (s_mutex);
fatal_error ("An unhandled exception was thrown");
}
private:
typedef CriticalSection LockType;
typedef CriticalSection::ScopedLockType ScopedLockType;
static LockType s_mutex;
};
ProtectedCall::DefaultHandler::LockType ProtectedCall::DefaultHandler::s_mutex;
//------------------------------------------------------------------------------
Static::Storage <Atomic <ProtectedCall::Handler const*>, ProtectedCall>
ProtectedCall::s_handler;
@@ -319,15 +335,19 @@ public:
{
}
void testThrow ()
{
throw std::runtime_error ("uncaught exception");
}
void runTest ()
{
beginTestCase ("backtrace");
beginTestCase ("throw");
String const s = SystemStats::getStackBacktrace ();
ProtectedCall (&ProtectedCallTests::testThrow, this);
logMessage (s);
pass ();
// If we get here then we failed
fail ();
}
};

View File

@@ -40,6 +40,11 @@
ProtectedCall (&funcThatMightThrow, 3);
@endcode
Every Beast Thread object's @ref Thread::run method is wrapped in a
@ProtectedCall
@see Thread, Throw
*/
class ProtectedCall
{
@@ -60,10 +65,7 @@ public:
};
/** The default handler writes to std::cerr makes the process exit. */
class DefaultHandler : public Handler
{
void onException (Exception const& e) const;
};
class DefaultHandler;
static void setHandler (Handler const& handler);