2020-08-25 05:00:23 +00:00
|
|
|
/*!********************************************************************
|
2017-11-09 18:32:29 +00:00
|
|
|
|
|
|
|
Audacity: A Digital Audio Editor
|
|
|
|
|
2020-08-25 05:00:23 +00:00
|
|
|
@file AudacityException.cpp
|
|
|
|
@brief Implements AudacityException and related
|
2017-11-09 18:32:29 +00:00
|
|
|
|
|
|
|
Paul Licameli
|
|
|
|
|
2020-08-25 05:00:23 +00:00
|
|
|
***********************************************************************/
|
2017-11-09 18:32:29 +00:00
|
|
|
|
2021-05-09 15:16:56 +00:00
|
|
|
|
2016-11-22 19:54:20 +00:00
|
|
|
#include "AudacityException.h"
|
|
|
|
|
|
|
|
#include <wx/atomic.h>
|
2017-09-06 21:39:33 +00:00
|
|
|
|
2019-05-20 18:27:11 +00:00
|
|
|
#include "widgets/AudacityMessageBox.h"
|
2020-09-10 11:58:14 +00:00
|
|
|
#include "widgets/ErrorDialog.h"
|
2016-11-22 19:54:20 +00:00
|
|
|
|
|
|
|
AudacityException::~AudacityException()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
wxAtomicInt sOutstandingMessages {};
|
|
|
|
|
2021-06-08 10:40:52 +00:00
|
|
|
MessageBoxException::MessageBoxException(
|
|
|
|
ExceptionType exceptionType_, const TranslatableString& caption_)
|
|
|
|
: caption { caption_ }
|
|
|
|
, exceptionType { exceptionType_ }
|
2016-11-22 19:54:20 +00:00
|
|
|
{
|
2017-10-21 03:22:07 +00:00
|
|
|
if (!caption.empty())
|
|
|
|
wxAtomicInc( sOutstandingMessages );
|
|
|
|
else
|
|
|
|
// invalidate me
|
|
|
|
moved = true;
|
2016-11-22 19:54:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The class needs a copy constructor to be throwable
|
|
|
|
// (or will need it, by C++14 rules). But the copy
|
|
|
|
// needs to act like a move constructor. There must be unique responsibility
|
|
|
|
// for each exception thrown to decrease the global count when it is handled.
|
|
|
|
MessageBoxException::MessageBoxException( const MessageBoxException& that )
|
|
|
|
{
|
|
|
|
caption = that.caption;
|
|
|
|
moved = that.moved;
|
2020-09-10 11:58:14 +00:00
|
|
|
helpUrl = that.helpUrl;
|
2021-06-08 10:40:52 +00:00
|
|
|
exceptionType = that.exceptionType;
|
2016-11-22 19:54:20 +00:00
|
|
|
that.moved = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageBoxException::~MessageBoxException()
|
|
|
|
{
|
|
|
|
if (!moved)
|
|
|
|
// If exceptions are used properly, you should never reach this,
|
|
|
|
// because moved should become true earlier in the object's lifetime.
|
|
|
|
wxAtomicDec( sOutstandingMessages );
|
|
|
|
}
|
|
|
|
|
2017-03-24 18:40:39 +00:00
|
|
|
SimpleMessageBoxException::~SimpleMessageBoxException()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-12-07 15:04:35 +00:00
|
|
|
TranslatableString SimpleMessageBoxException::ErrorMessage() const
|
2017-03-24 18:40:39 +00:00
|
|
|
{
|
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
2016-11-22 19:54:20 +00:00
|
|
|
// This is meant to be invoked via wxEvtHandler::CallAfter
|
|
|
|
void MessageBoxException::DelayedHandlerAction()
|
|
|
|
{
|
|
|
|
if (!moved) {
|
|
|
|
// This test prevents accumulation of multiple messages between idle
|
|
|
|
// times of the main even loop. Only the last queued exception
|
|
|
|
// displays its message. We assume that multiple messages have a
|
|
|
|
// common cause such as exhaustion of disk space so that the others
|
|
|
|
// give the user no useful added information.
|
2020-09-10 11:58:14 +00:00
|
|
|
|
2020-09-22 17:10:26 +00:00
|
|
|
if ( wxAtomicDec( sOutstandingMessages ) == 0 ) {
|
2021-06-08 10:40:52 +00:00
|
|
|
if (exceptionType == ExceptionType::Internal)
|
|
|
|
{
|
|
|
|
ShowExceptionDialog(
|
|
|
|
nullptr,
|
|
|
|
(caption.empty() ? AudacityMessageBoxCaptionStr() : caption),
|
|
|
|
ErrorMessage(), ErrorHelpUrl());
|
|
|
|
}
|
|
|
|
// We show BadEnvironment and BadUserAction in a similar way
|
|
|
|
else if (ErrorHelpUrl().IsEmpty())
|
2020-09-10 11:58:14 +00:00
|
|
|
{
|
|
|
|
::AudacityMessageBox(
|
|
|
|
ErrorMessage(),
|
|
|
|
(caption.empty() ? AudacityMessageBoxCaptionStr() : caption),
|
2021-06-08 10:40:52 +00:00
|
|
|
wxICON_ERROR);
|
2020-09-10 11:58:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ShowErrorDialog(
|
|
|
|
nullptr,
|
|
|
|
(caption.empty() ? AudacityMessageBoxCaptionStr() : caption),
|
2021-06-08 10:40:52 +00:00
|
|
|
ErrorMessage(), ErrorHelpUrl());
|
2020-09-10 11:58:14 +00:00
|
|
|
}
|
2020-09-22 17:10:26 +00:00
|
|
|
}
|
2020-09-10 11:58:14 +00:00
|
|
|
|
2016-11-22 19:54:20 +00:00
|
|
|
moved = true;
|
|
|
|
}
|
|
|
|
}
|