1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-03 06:03:13 +02:00

Merge pull request #1322 from Paul-Licameli/extract-lib-exceptions

Extract lib exceptions
This commit is contained in:
Paul Licameli 2021-07-21 14:04:02 -04:00 committed by GitHub
commit 21fc0947f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
63 changed files with 127 additions and 42 deletions

View File

@ -9,6 +9,7 @@ set( LIBRARIES
lib-uuid
lib-components
lib-basic-ui
lib-exceptions
)
if ( ${_OPT}has_networking )

View File

@ -219,7 +219,7 @@ BASIC_UI_API Services *Install(Services *pInstance);
are yet installed, the action is not lost, but may be dispatched by Yield().
The action may itself invoke CallAfter to enqueue other actions.
*/
void CallAfter(Action action);
BASIC_UI_API void CallAfter(Action action);
//! Dispatch waiting events, including actions enqueued by CallAfter
/*! This function must be called by the main thread. Actions enqueued by
@ -227,7 +227,7 @@ void CallAfter(Action action);
they were enqueued, unless an exception thrown by one of them stops the
dispatching.
*/
void Yield();
BASIC_UI_API void Yield();
//! Show an error dialog with a link to the manual for further help
inline void ShowErrorDialog(

View File

@ -9,7 +9,6 @@
***********************************************************************/
#include "AudacityException.h"
#include <wx/atomic.h>
@ -20,6 +19,21 @@ AudacityException::~AudacityException()
{
}
void AudacityException::EnqueueAction(
std::exception_ptr pException,
std::function<void(AudacityException*)> delayedHandler)
{
BasicUI::CallAfter( [
pException = std::move(pException), delayedHandler = std::move(delayedHandler)
] {
try {
std::rethrow_exception(pException);
}
catch( AudacityException &e )
{ delayedHandler( &e ); }
} );
}
wxAtomicInt sOutstandingMessages {};
MessageBoxException::MessageBoxException(

View File

@ -12,8 +12,8 @@
**********************************************************************/
#include "MemoryX.h"
#include <wx/app.h> // used in inline function template
#include <exception>
#include <functional>
#include "Internat.h"
@ -38,22 +38,26 @@ public:
//! Action to do in the main thread at idle time of the event loop.
virtual void DelayedHandlerAction() = 0;
EXCEPTIONS_API static void EnqueueAction(
std::exception_ptr pException,
std::function<void(AudacityException*)> delayedHandler);
protected:
//! Make this protected to prevent slicing copies
AudacityException( const AudacityException& ) = default;
//! Don't allow moves of this class or subclasses
// see https://bugzilla.audacityteam.org/show_bug.cgi?id=2442
AudacityException( AudacityException&& ) = delete;
AudacityException( AudacityException&& ) PROHIBITED;
//! Disallow assignment
AudacityException &operator = ( const AudacityException & ) = delete;
AudacityException &operator = ( const AudacityException & ) PROHIBITED;
};
//! Abstract AudacityException subclass displays a message, specified by further subclass
/*! At most one message will be displayed for each pass through the main event idle loop,
no matter how many exceptions were caught. */
class AUDACITY_DLL_API MessageBoxException /* not final */
class EXCEPTIONS_API MessageBoxException /* not final */
: public AudacityException
{
//! Privatize the inherited function
@ -86,7 +90,7 @@ protected:
};
//! A MessageBoxException that shows a given, unvarying string.
class AUDACITY_DLL_API SimpleMessageBoxException /* not final */
class EXCEPTIONS_API SimpleMessageBoxException /* not final */
: public MessageBoxException
{
public:
@ -191,17 +195,16 @@ template <
typename F1, // function object with signature R()
typename F2 = SimpleGuard< R >, // function object
typename F2 = SimpleGuard< R > // function object
// with signature R( AudacityException * )
typename F3 =
DefaultDelayedHandlerAction // Any( AudacityException * ), ignore return
>
//! Execute some code on any thread; catch any AudacityException; enqueue error report on the main thread
R GuardedCall(
const F1 &body, //!< typically a lambda
const F2 &handler = F2::Default(), //!< default just returns false or void; see also @ref MakeSimpleGuard
const F3 &delayedHandler = {} //!< called later in the main thread, passing it a stored exception; usually defaulted
std::function<void(AudacityException*)> delayedHandler
= DefaultDelayedHandlerAction{} /*!<called later in the main thread,
passing it a stored exception; usually defaulted */
)
{
try { return body(); }
@ -213,11 +216,8 @@ R GuardedCall(
// other exception object.
if (!std::uncaught_exception()) {
auto pException = std::current_exception(); // This points to e
wxTheApp->CallAfter( [=] { // capture pException by value
try { std::rethrow_exception(pException); }
catch( AudacityException &e )
{ delayedHandler( &e ); }
} );
AudacityException::EnqueueAction(
pException, std::move(delayedHandler));
}
});

View File

@ -0,0 +1,34 @@
#[[
Toolkit neutral library for exceptions.
Abstract class AudacityException with a member function for a delayed
handler action, enqueued in the main thread;
Some commonly useful subclasses, with delayed handlers that are no-ops or
are displays of messages to the user;
Function template GuardedCall which stops propagation of exceptions and
enqueues the delayed action.
But this library does NOT define a top-level handler for the whole application,
to catch all otherwise uncaught exceptions. That is a responsibility of high
level code.
]]#
list( APPEND SOURCES
AudacityException.cpp
AudacityException.h
InconsistencyException.cpp
InconsistencyException.h
UserException.cpp
UserException.h
)
set( LIBRARIES
lib-utility-interface
lib-basic-ui-interface
PRIVATE
wxBase
)
audacity_library( lib-exceptions "${SOURCES}" "${LIBRARIES}"
"" ""
)

View File

@ -7,8 +7,8 @@
*/
#include "InconsistencyException.h"
#include <wx/filename.h>
InconsistencyException::~InconsistencyException()
{

View File

@ -20,7 +20,7 @@
The error message identifies source file and line number, possibly the function too (depending on
the compiler), and suggests that the user inform the development team.
*/
class AUDACITY_DLL_API InconsistencyException final : public MessageBoxException
class EXCEPTIONS_API InconsistencyException final : public MessageBoxException
{
public:
InconsistencyException ()

View File

@ -6,7 +6,6 @@
*/
#include "UserException.h"
UserException::~UserException()

View File

@ -13,7 +13,7 @@
//! Can be thrown when user cancels operations, as with a progress dialog. Delayed handler does nothing
/*! This class does not inherit from MessageBoxException. */
class AUDACITY_DLL_API UserException final : public AudacityException
class EXCEPTIONS_API UserException final : public AudacityException
{
public:
UserException() {}

View File

@ -21,8 +21,7 @@
#include "AdornedRulerPanel.h"
#include <wx/app.h>
#include <wx/setup.h> // for wxUSE_* macros
#include <wx/tooltip.h>

View File

@ -23,6 +23,7 @@ processing. See also MacrosWindow and ApplyMacroDialog.
#include <wx/defs.h>
#include <wx/datetime.h>
#include <wx/dir.h>
#include <wx/log.h>
#include <wx/textfile.h>
#include <wx/time.h>

View File

@ -27,6 +27,7 @@
#include <wx/checkbox.h>
#include <wx/choice.h>
#include <wx/intl.h>
#include <wx/log.h>
#include <wx/sizer.h>
#include <wx/statbox.h>
#include <wx/stattext.h>

View File

@ -88,8 +88,6 @@ list( APPEND SOURCES
AudacityApp.cpp
AudacityApp.h
$<$<BOOL:${wxIS_MAC}>:AudacityApp.mm>
AudacityException.cpp
AudacityException.h
AudacityFileConfig.cpp
AudacityFileConfig.h
AudacityHeaders.cpp
@ -159,8 +157,6 @@ list( APPEND SOURCES
HitTestResult.h
ImageManipulation.cpp
ImageManipulation.h
InconsistencyException.cpp
InconsistencyException.h
InterpolateAudio.cpp
InterpolateAudio.h
KeyboardCapture.cpp
@ -325,8 +321,6 @@ list( APPEND SOURCES
UIHandle.h
UndoManager.cpp
UndoManager.h
UserException.cpp
UserException.h
ViewInfo.cpp
ViewInfo.h
VoiceKey.cpp

View File

@ -24,9 +24,11 @@
#endif
#ifndef WX_PRECOMP
#include <wx/app.h>
#include <wx/choice.h>
#include <wx/event.h>
#include <wx/intl.h>
#include <wx/log.h>
#include <wx/settings.h>
#include <wx/sizer.h>
#include <wx/statbmp.h>

View File

@ -38,6 +38,7 @@ a draggable point type.
#include <wx/pen.h>
#include <wx/textfile.h>
#include <wx/log.h>
#include <wx/utils.h>
static const double VALUE_TOLERANCE = 0.001;

View File

@ -19,6 +19,7 @@
#include <gtk/gtk.h>
#endif
#include <wx/app.h>
#include <wx/button.h>
#include <wx/eventfilter.h>
#include <wx/toplevel.h>

View File

@ -41,6 +41,7 @@ for drawing different aspects of the label and its text box.
#include <limits.h>
#include <float.h>
#include <wx/log.h>
#include <wx/tokenzr.h>
#include "Prefs.h"

View File

@ -13,6 +13,7 @@
#include <math.h>
#include <wx/app.h>
#include <wx/dcclient.h>
#include <wx/defs.h>
#include <wx/dcmemory.h>

View File

@ -19,6 +19,7 @@
#include "ProjectFileIO.h"
#include "ViewInfo.h"
#include <wx/app.h>
#include <wx/radiobut.h>
#include <wx/toolbar.h>
#include <wx/settings.h>

View File

@ -19,6 +19,7 @@
#include <wx/setup.h> // for wxUSE_* macros
#include <wx/app.h>
#include <wx/bmpbuttn.h>
#include <wx/dcclient.h>
#include <wx/icon.h>

View File

@ -17,6 +17,7 @@
#include "TempDirectory.h"
#include "widgets/wxWidgetsBasicUI.h"
#include <wx/app.h>
#include <wx/display.h>
#include <wx/filename.h>
#include <wx/frame.h>

View File

@ -11,8 +11,7 @@ Paul Licameli split from ProjectManager.cpp
#include "ProjectAudioManager.h"
#include <wx/app.h>
#include <wx/frame.h>
#include <wx/statusbr.h>

View File

@ -16,6 +16,7 @@ Paul Licameli split from ProjectManager.h
#include "AudioIOListener.h" // to inherit
#include "ClientData.h" // to inherit
#include <wx/event.h> // to declare custom event type
constexpr int RATE_NOT_SELECTED{ -1 };

View File

@ -12,6 +12,7 @@ Paul Licameli split from AudacityProject.cpp
#include <atomic>
#include <sqlite3.h>
#include <wx/app.h>
#include <wx/crt.h>
#include <wx/frame.h>
#include <wx/sstream.h>

View File

@ -17,6 +17,7 @@ Paul Licameli split from AudacityProject.cpp
#endif
#include <wx/frame.h>
#include <wx/log.h>
#include "BasicUI.h"
#include "CodeConversions.h"
#include "Legacy.h"

View File

@ -46,6 +46,7 @@ Paul Licameli split from AudacityProject.cpp
#include "widgets/FileHistory.h"
#include "widgets/WindowAccessible.h"
#include <wx/app.h>
#include <wx/dataobj.h>
#include <wx/dnd.h>
#include <wx/scrolbar.h>

View File

@ -33,6 +33,7 @@ Paul Licameli split from AudacityProject.cpp
#include "widgets/wxPanelWrapper.h"
#include "widgets/WindowAccessible.h"
#include <wx/app.h>
#include <wx/display.h>
#include <wx/scrolbar.h>
#include <wx/sizer.h>

View File

@ -20,6 +20,7 @@ It forwards the actual work of doing the commands to the ScreenshotCommand.
#include "commands/ScreenshotCommand.h"
#include "commands/CommandTargets.h"
#include "commands/CommandContext.h"
#include <wx/app.h>
#include <wx/defs.h>
#include <wx/event.h>
#include <wx/frame.h>

View File

@ -19,6 +19,7 @@ Paul Licameli -- split from SampleBlock.cpp and SampleBlock.h
#include "SampleBlock.h" // to inherit
#include "SentryHelper.h"
#include <wx/log.h>
class SqliteSampleBlockFactory;
@ -1029,4 +1030,4 @@ static struct Injector
);
}
} injector;

View File

@ -40,6 +40,7 @@
#ifndef WX_PRECOMP
// Include your minimal set of headers here, or wx.h
#include <wx/log.h>
#include <wx/window.h>
#endif

View File

@ -19,6 +19,7 @@
#include <vector>
#include <list>
#include <functional>
#include <wx/event.h> // to inherit wxCommandEvent
#include <wx/longlong.h>
#include "ClientData.h"

View File

@ -28,8 +28,7 @@ Paul Licameli split from TrackPanel.cpp
#include "TrackInfo.h"
#include <wx/app.h>
#include <wx/dc.h>
#include <wx/frame.h>

View File

@ -46,8 +46,7 @@ is time to refresh some aspect of the screen.
#include "TrackPanel.h"
#include <wx/app.h>
#include <wx/setup.h> // for wxUSE_* macros
#include "AdornedRulerPanel.h"

View File

@ -89,7 +89,7 @@ classes derived from it.
#include "CommandContext.h"
#include "../AudacityException.h"
#include "AudacityException.h"

View File

@ -82,6 +82,7 @@ CommandManager. It holds the callback for one command.
#include "CommandContext.h"
#include "CommandManagerWindowClasses.h"
#include <wx/app.h>
#include <wx/defs.h>
#include <wx/evtloop.h>
#include <wx/frame.h>

View File

@ -48,6 +48,7 @@ This class now lists
#include "../ShuttleGui.h"
#include <wx/frame.h>
#include <wx/log.h>
#include <wx/menu.h>
const ComponentInterfaceSymbol GetInfoCommand::Symbol

View File

@ -24,6 +24,7 @@ small calculations of rectangles.
#include "LoadCommands.h"
#include "../Project.h"
#include <wx/app.h>
#include <wx/toplevel.h>
#include <wx/dcscreen.h>
#include <wx/dcmemory.h>

View File

@ -660,6 +660,7 @@ private:
#include "../widgets/AudacityMessageBox.h"
#include "../widgets/HelpSystem.h"
#include <wx/app.h>
#include <wx/bmpbuttn.h>
#include <wx/checkbox.h>
#include <wx/dcclient.h>

View File

@ -69,6 +69,7 @@
#include <wx/dcmemory.h>
#include <wx/event.h>
#include <wx/listctrl.h>
#include <wx/log.h>
#include <wx/image.h>
#include <wx/intl.h>
#include <wx/choice.h>

View File

@ -24,6 +24,7 @@ function.
#include "../FFmpeg.h"
#include <wx/choice.h>
#include <wx/log.h>
#include <wx/intl.h>
#include <wx/timer.h>
#include <wx/string.h>

View File

@ -46,6 +46,7 @@
#include "../FFmpeg.h"
#include <wx/app.h>
#include <wx/checkbox.h>
#include <wx/choice.h>
#include <wx/intl.h>

View File

@ -29,6 +29,7 @@
#include <wx/filefn.h>
#include <wx/filename.h>
#include <wx/intl.h>
#include <wx/log.h>
#include <wx/radiobut.h>
#include <wx/simplebook.h>
#include <wx/sizer.h>

View File

@ -12,6 +12,7 @@
#include <wx/defs.h>
#include <wx/app.h>
#include <wx/choice.h>
#include <wx/dynlib.h>
#include <wx/filename.h>

View File

@ -59,6 +59,7 @@ static const auto exts = {wxT("aup")};
#include <wx/ffile.h>
#include <wx/file.h>
#include <wx/frame.h>
#include <wx/log.h>
#include <wx/string.h>
#include <wx/utils.h>

View File

@ -28,6 +28,7 @@ Licensed under the GNU General Public License v2 or later
#include "../FFmpeg.h" // which brings in avcodec.h, avformat.h
#ifndef WX_PRECOMP
// Include your minimal set of headers here, or wx.h
#include <wx/log.h>
#include <wx/window.h>
#endif

View File

@ -31,7 +31,7 @@ and sample size to help you importing data of an unknown format.
#include "../Prefs.h"
#include "../ProjectSettings.h"
#include "../ShuttleGui.h"
#include "../UserException.h"
#include "UserException.h"
#include "../WaveTrack.h"
#include "../widgets/ProgressDialog.h"

View File

@ -16,7 +16,7 @@
#include "RawAudioGuess.h"
#include "../AudacityException.h"
#include "AudacityException.h"
#include <stdio.h>
#include <stdlib.h>

View File

@ -32,6 +32,7 @@
#include "../import/ImportMIDI.h"
#endif // USE_MIDI
#include <wx/app.h>
#include <wx/menu.h>
// private helper classes and functions

View File

@ -1,5 +1,5 @@
#include <wx/app.h>
#include <wx/bmpbuttn.h>
#include <wx/textctrl.h>
#include <wx/frame.h>

View File

@ -25,6 +25,8 @@
#include "../prefs/EffectsPrefs.h"
#include "../prefs/PrefsDialog.h"
#include <wx/log.h>
// private helper classes and functions
namespace {

View File

@ -34,6 +34,7 @@
#include "../widgets/ProgressDialog.h"
#include <float.h>
#include <wx/app.h>
// private helper classes and functions
namespace {

View File

@ -20,6 +20,7 @@
#include "../effects/EffectUI.h"
#endif
#include <wx/app.h>
#include <wx/scrolbar.h>
// private helper classes and functions

View File

@ -24,6 +24,7 @@
#include <wx/setup.h> // for wxUSE_* macros
#ifndef WX_PRECOMP
#include <wx/app.h>
#include <wx/choice.h>
#include <wx/event.h>
#include <wx/intl.h>

View File

@ -39,6 +39,7 @@
#include <wx/setup.h> // for wxUSE_* macros
#ifndef WX_PRECOMP
#include <wx/app.h>
#include <wx/event.h>
#include <wx/image.h>
#include <wx/intl.h>

View File

@ -23,6 +23,7 @@
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/app.h>
#include <wx/choice.h>
#include <wx/event.h>
#include <wx/intl.h>

View File

@ -29,6 +29,7 @@ Paul Licameli split from TrackPanel.cpp
#include "../../../../prefs/ThemePrefs.h"
#include <mutex>
#include <wx/app.h>
#include <wx/frame.h>
///////////////////////////////////////////////////////////////////////////////

View File

@ -36,6 +36,7 @@ Paul Licameli split from TrackPanel.cpp
#include "UserException.h"
#include "Identifier.h"
#include <wx/app.h>
#include <wx/combobox.h>
#include <wx/frame.h>
#include <wx/sizer.h>

View File

@ -23,6 +23,8 @@ class WaveTrack;
class WaveTrackView;
class WaveClip;
class wxDC;
class AUDACITY_DLL_API WaveTrackSubView : public CommonTrackView
{
public:

View File

@ -33,6 +33,7 @@ Paul Licameli split from TrackPanel.cpp
#include <algorithm>
#include <wx/app.h>
#include <wx/menu.h>
// Yet another experimental scrub would drag the track under a

View File

@ -27,6 +27,7 @@ class Track;
class TrackInterval;
class ViewInfo;
class wxMouseState;
//! Abstract base class for policies to manipulate a track type with the Time Shift tool
class AUDACITY_DLL_API TrackShifter {

View File

@ -11,6 +11,7 @@
#include "xml/XMLFileReader.h"
#include "MemoryX.h"
#include <wx/platinfo.h>
UpdateDataParser::UpdateDataParser()
{}

View File

@ -18,9 +18,9 @@
#include "IResponse.h"
#include "Request.h"
#include <wx/platinfo.h>
#include <wx/utils.h>
#include <wx/frame.h>
#include <wx/app.h>
#include <mutex>
#include <cstdint>

View File

@ -18,6 +18,7 @@
#include <wx/defs.h>
#include <wx/ffile.h>
#include <wx/intl.h>
#include <wx/log.h>
#include <string.h>