Audacity  3.0.3
Classes | Functions
AudacityException.h File Reference

Declare abstract class AudacityException, some often-used subclasses, and GuardedCall. More...

#include "MemoryX.h"
#include <wx/app.h>
#include <exception>
#include "Internat.h"
Include dependency graph for AudacityException.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  AudacityException
 Base class for exceptions specially processed by the application. More...
 
class  MessageBoxException
 Abstract AudacityException subclass displays a message, specified by further subclass. More...
 
class  SimpleMessageBoxException
 A MessageBoxException that shows a given, unvarying string. More...
 
struct  DefaultDelayedHandlerAction
 A default template parameter for GuardedCall. More...
 
struct  SimpleGuard< R >
 A default template parameter for GuardedCall<R> More...
 
struct  SimpleGuard< bool >
 Specialization of SimpleGuard, also defining a default value. More...
 
struct  SimpleGuard< void >
 Specialization of SimpleGuard, also defining a default value. More...
 

Functions

template<typename R >
SimpleGuard< R > MakeSimpleGuard (R value)
 Convert a value to a handler function returning that value, suitable for GuardedCall<R> More...
 
SimpleGuard< void > MakeSimpleGuard ()
 Convert a value to a no-op handler function, suitable for GuardedCall<void> More...
 
template<typename R = void, typename F1 , typename F2 = SimpleGuard< R >, typename F3 = DefaultDelayedHandlerAction>
GuardedCall (const F1 &body, const F2 &handler=F2::Default(), const F3 &delayedHandler={})
 Execute some code on any thread; catch any AudacityException; enqueue error report on the main thread. More...
 

Detailed Description

Declare abstract class AudacityException, some often-used subclasses, and GuardedCall.


Audacity: A Digital Audio Editor

Paul Licameli

Definition in file AudacityException.h.

Function Documentation

◆ GuardedCall()

template<typename R = void, typename F1 , typename F2 = SimpleGuard< R >, typename F3 = DefaultDelayedHandlerAction>
R GuardedCall ( const F1 &  body,
const F2 &  handler = F2::Default(),
const F3 &  delayedHandler = {} 
)

Execute some code on any thread; catch any AudacityException; enqueue error report on the main thread.

Executes a given function (typically a lamba), in any thread.

If there is any exception, can invoke another given function as handler, which may rethrow that or another exception, but usually just returns the value for the GuardedCall.

If AudacityException is handled, then it queues up a delayed handler action for execution later in the event loop at idle time, on the main thread; typically this informs the user of the error.

The default delayed handler action is simply to invoke a method of the AudacityException, but this too can be specified otherwise by a third function.

Template Parameters
RReturn type, defaulted to void, or else the only explicit template parameter
F1deduced type of body function; takes no arguments, returns R
F2deduced type of handler function, or defaulted to SimpleGuard<R>; takes pointer to AudacityException, which is null when some other type of exception is caught; return value is converted to R
F3deduced type of delayed handler function, if a nondefault argument is given; takes pointer to AudacityException, return value is unused
Parameters
bodytypically a lambda
handlerdefault just returns false or void; see also MakeSimpleGuard
delayedHandlercalled later in the main thread, passing it a stored exception; usually defaulted

Definition at line 187 of file AudacityException.h.

190  {}
191 )
192 {
193  try { return body(); }
194  catch ( AudacityException &e ) {
195 
196  auto end = finally([&]{
197  // At this point, e is the "current" exception, but not "uncaught"
198  // unless it was rethrown by handler. handler might also throw some
199  // other exception object.
200  if (!std::uncaught_exception()) {
201  auto pException = std::current_exception(); // This points to e
202  wxTheApp->CallAfter( [=] { // capture pException by value
203  try { std::rethrow_exception(pException); }
204  catch( AudacityException &e )
205  { delayedHandler( &e ); }
206  } );
207  }
208  });
209 
210  return handler( &e );
211  }
212  catch ( ... ) {
213  return handler( nullptr );
214  }
215 }

Referenced by MacroCommands::ApplyMacro(), DBConnection::CheckpointThread(), ExportPCM::Export(), FFmpegPresets::ExportPresets(), AudioIO::FillBuffers(), AUPImportFileHandle::HandleImport(), KeyConfigPrefs::OnExport(), ExportMultipleDialog::OnExport(), TagsEditorDialog::OnSave(), Effect::Preview(), ProjectFSCK(), EffectEqualization::SaveCurves(), AudioIO::StopStream(), FFmpegPresets::~FFmpegPresets(), SqliteSampleBlock::~SqliteSampleBlock(), and XMLFileWriter::~XMLFileWriter().

Here is the caller graph for this function:

◆ MakeSimpleGuard() [1/2]

SimpleGuard< void > MakeSimpleGuard ( )
inline

Convert a value to a no-op handler function, suitable for GuardedCall<void>

Definition at line 153 of file AudacityException.h.

153 { return {}; }

◆ MakeSimpleGuard() [2/2]

template<typename R >
SimpleGuard< R > MakeSimpleGuard ( value)

Convert a value to a handler function returning that value, suitable for GuardedCall<R>

Definition at line 149 of file AudacityException.h.

150 { return SimpleGuard< R >{ value }; }

Referenced by MP3ImportFileHandle::ErrorCB(), ExecCallback(), MP3ImportFileHandle::filter_cb(), GStreamerNewSample(), MP3ImportFileHandle::input_cb(), MP3ImportFileHandle::OutputCB(), and NyquistEffect::PutCallback().

Here is the caller graph for this function:
SimpleGuard
A default template parameter for GuardedCall<R>
Definition: AudacityException.h:117
AudacityException
Base class for exceptions specially processed by the application.
Definition: AudacityException.h:25