diff --git a/src/AudacityApp.cpp b/src/AudacityApp.cpp index 42da742d3..58ef81a9e 100644 --- a/src/AudacityApp.cpp +++ b/src/AudacityApp.cpp @@ -1083,7 +1083,7 @@ bool AudacityApp::OnExceptionInMainLoop() // Use CallAfter to delay this to the next pass of the event loop, // rather than risk doing it inside stack unwinding. auto pProject = ::GetActiveProject(); - std::shared_ptr< AudacityException > pException { e.Move().release() }; + auto pException = std::current_exception(); CallAfter( [=] // Capture pException by value! { @@ -1097,7 +1097,9 @@ bool AudacityApp::OnExceptionInMainLoop() pProject->RedrawProject(); // Give the user an alert - pException->DelayedHandlerAction(); + try { std::rethrow_exception( pException ); } + catch( AudacityException &e ) + { e.DelayedHandlerAction(); } } ); diff --git a/src/AudacityException.cpp b/src/AudacityException.cpp index deb9e9424..4a8b18229 100644 --- a/src/AudacityException.cpp +++ b/src/AudacityException.cpp @@ -85,12 +85,6 @@ wxString SimpleMessageBoxException::ErrorMessage() const return message; } -std::unique_ptr< AudacityException > SimpleMessageBoxException::Move() -{ - return std::unique_ptr< AudacityException > - { safenew SimpleMessageBoxException{ std::move( *this ) } }; -} - // This is meant to be invoked via wxEvtHandler::CallAfter void MessageBoxException::DelayedHandlerAction() { diff --git a/src/AudacityException.h b/src/AudacityException.h index 8d86dcc0e..f8662a40b 100644 --- a/src/AudacityException.h +++ b/src/AudacityException.h @@ -30,11 +30,6 @@ public: AudacityException() {} virtual ~AudacityException() = 0; - // This is intended as a "polymorphic move copy constructor" - // which leaves this "empty". - // We would not need this if we had std::exception_ptr - virtual std::unique_ptr< AudacityException > Move() = 0; - // Action to do in the main thread at idle time of the event loop. virtual void DelayedHandlerAction() = 0; @@ -88,8 +83,6 @@ public: SimpleMessageBoxException &operator = ( SimpleMessageBoxException && ) PROHIBITED; - std::unique_ptr< AudacityException > Move() override; - // Format a default, internationalized error message for this exception. virtual wxString ErrorMessage() const override; @@ -170,11 +163,15 @@ R GuardedCall catch ( AudacityException &e ) { auto end = finally([&]{ + // At this point, e is the "current" exception, but not "uncaught" + // unless it was rethrown by handler. handler might also throw some + // other exception object. if (!std::uncaught_exception()) { - auto pException = - std::shared_ptr< AudacityException > { e.Move().release() }; + auto pException = std::current_exception(); // This points to e wxTheApp->CallAfter( [=] { // capture pException by value - delayedHandler( pException.get() ); + try { std::rethrow_exception(pException); } + catch( AudacityException &e ) + { delayedHandler( &e ); } } ); } }); diff --git a/src/FileException.cpp b/src/FileException.cpp index 21c63ef62..b9bdfccd7 100644 --- a/src/FileException.cpp +++ b/src/FileException.cpp @@ -15,12 +15,6 @@ FileException::~FileException() { } -std::unique_ptr< AudacityException > FileException::Move() -{ - return std::unique_ptr< AudacityException > - { safenew FileException{ std::move( *this ) } }; -} - wxString FileException::ErrorMessage() const { wxString format; diff --git a/src/FileException.h b/src/FileException.h index 6a6fcb6ec..9f624be63 100644 --- a/src/FileException.h +++ b/src/FileException.h @@ -37,8 +37,6 @@ public: ~FileException() override; protected: - std::unique_ptr< AudacityException > Move() override; - // Format a default, internationalized error message for this exception. wxString ErrorMessage() const override; diff --git a/src/InconsistencyException.cpp b/src/InconsistencyException.cpp index 73db17a6b..33cdc5292 100644 --- a/src/InconsistencyException.cpp +++ b/src/InconsistencyException.cpp @@ -14,12 +14,6 @@ InconsistencyException::~InconsistencyException() { } -std::unique_ptr< AudacityException > InconsistencyException::Move() -{ - return std::unique_ptr< AudacityException > - { safenew InconsistencyException{ std::move( *this ) } }; -} - wxString InconsistencyException::ErrorMessage() const { // Shorten the path diff --git a/src/InconsistencyException.h b/src/InconsistencyException.h index 2012203fe..78477b263 100644 --- a/src/InconsistencyException.h +++ b/src/InconsistencyException.h @@ -48,8 +48,6 @@ public: unsigned GetLine() const { return line; } private: - std::unique_ptr< AudacityException > Move() override; - // Format a default, internationalized error message for this exception. wxString ErrorMessage() const override; diff --git a/src/UserException.cpp b/src/UserException.cpp index f26502d14..6229bc5bb 100644 --- a/src/UserException.cpp +++ b/src/UserException.cpp @@ -13,12 +13,6 @@ UserException::~UserException() { } -std::unique_ptr< AudacityException > UserException::Move() -{ - return std::unique_ptr< AudacityException > - { safenew UserException{ std::move( *this ) } }; -} - void UserException::DelayedHandlerAction() { } diff --git a/src/UserException.h b/src/UserException.h index e59b881cc..da0fd7e94 100644 --- a/src/UserException.h +++ b/src/UserException.h @@ -30,9 +30,6 @@ public: ~UserException() override; void DelayedHandlerAction() override; - -private: - std::unique_ptr< AudacityException > Move() override; }; #endif diff --git a/src/blockfile/NotYetAvailableException.cpp b/src/blockfile/NotYetAvailableException.cpp index 0d01275dc..356534bd9 100644 --- a/src/blockfile/NotYetAvailableException.cpp +++ b/src/blockfile/NotYetAvailableException.cpp @@ -14,12 +14,6 @@ NotYetAvailableException::~NotYetAvailableException() { } -std::unique_ptr< AudacityException > NotYetAvailableException::Move() -{ - return std::unique_ptr< AudacityException > - { safenew NotYetAvailableException{ std::move( *this ) } }; -} - wxString NotYetAvailableException::ErrorMessage() const { return wxString::Format( diff --git a/src/blockfile/NotYetAvailableException.h b/src/blockfile/NotYetAvailableException.h index d961bcec7..cc375c15c 100644 --- a/src/blockfile/NotYetAvailableException.h +++ b/src/blockfile/NotYetAvailableException.h @@ -25,7 +25,6 @@ public: ~NotYetAvailableException(); protected: - std::unique_ptr< AudacityException > Move() override; wxString ErrorMessage() const override; };