Audacity  2.2.2
Classes | Functions
AudacityException.h File Reference
#include "MemoryX.h"
#include <wx/app.h>
#include <exception>
#include "Internat.h"

Go to the source code of this file.

Classes

class  AudacityException
 root of a hierarchy of classes that are thrown and caught by Audacity. More...
 
class  MessageBoxException
 an AudacityException that pops up a single message box even if there were multiple exceptions of the same kind before it actually got to show. More...
 
class  SimpleMessageBoxException
 
struct  DefaultDelayedHandlerAction
 
struct  SimpleGuard< R >
 
struct  SimpleGuard< bool >
 
struct  SimpleGuard< void >
 

Functions

template<typename R >
SimpleGuard< R > MakeSimpleGuard (R value)
 
SimpleGuard< void > MakeSimpleGuard ()
 
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={})
 

Function Documentation

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 = {} 
)

Call the body function (usually a lambda) inside a try block.

The handler intercepts exceptions, and is passed nullptr if the exception is of a type not defined by Audacity. It may return a value for the guarded call or throw the same or another exception. It executes in the same thread as the body.

If the handler is passed non-null and does not throw, then delayedHandler executes later in the main thread, in idle time of the event loop.

Definition at line 158 of file AudacityException.h.

Referenced by AudioIO::FillBuffers(), ImportXMLTagHandler::HandleXMLTag(), KeyConfigPrefs::OnExport(), ExportMultiple::OnExport(), TagsEditor::OnSave(), Effect::Preview(), DirManager::ProjectFSCK(), EffectEqualization::SaveCurves(), AudioIO::StopStream(), and XMLFileWriter::~XMLFileWriter().

160  {} )
161 {
162  try { return body(); }
163  catch ( AudacityException &e ) {
164 
165  auto end = finally([&]{
166  // At this point, e is the "current" exception, but not "uncaught"
167  // unless it was rethrown by handler. handler might also throw some
168  // other exception object.
169  if (!std::uncaught_exception()) {
170  auto pException = std::current_exception(); // This points to e
171  wxTheApp->CallAfter( [=] { // capture pException by value
172  try { std::rethrow_exception(pException); }
173  catch( AudacityException &e )
174  { delayedHandler( &e ); }
175  } );
176  }
177  });
178 
179  return handler( &e );
180  }
181  catch ( ... ) {
182  return handler( nullptr );
183  }
184 }
root of a hierarchy of classes that are thrown and caught by Audacity.
template<typename R >
SimpleGuard< R > MakeSimpleGuard ( value)
SimpleGuard< void > MakeSimpleGuard ( )
inline

Definition at line 133 of file AudacityException.h.

133 { return {}; }