diff --git a/modules/beast_core/diagnostic/beast_ProtectedCall.cpp b/modules/beast_core/diagnostic/beast_ProtectedCall.cpp index d54ff4a62..1e862138d 100644 --- a/modules/beast_core/diagnostic/beast_ProtectedCall.cpp +++ b/modules/beast_core/diagnostic/beast_ProtectedCall.cpp @@ -277,9 +277,25 @@ bool CatchAny (Function 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 , 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 (); } }; diff --git a/modules/beast_core/diagnostic/beast_ProtectedCall.h b/modules/beast_core/diagnostic/beast_ProtectedCall.h index d86f5354e..d6013c011 100644 --- a/modules/beast_core/diagnostic/beast_ProtectedCall.h +++ b/modules/beast_core/diagnostic/beast_ProtectedCall.h @@ -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);