1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-11-28 16:20:12 +01:00

Define an AudacityException subclass for file errors

This commit is contained in:
Paul Licameli
2016-11-22 14:56:13 -05:00
parent f1cce8aa78
commit 195509a033
6 changed files with 107 additions and 0 deletions

45
src/FileException.cpp Normal file
View File

@@ -0,0 +1,45 @@
//
// FileException.cpp
//
//
// Created by Paul Licameli on 11/22/16.
//
//
#include "Audacity.h"
#include "FileException.h"
FileException::~FileException()
{
}
std::unique_ptr< AudacityException > FileException::Move()
{
return std::unique_ptr< AudacityException >
{ safenew FileException{ std::move( *this ) } };
}
wxString FileException::ErrorMessage() const
{
wxString format;
switch (cause) {
case Cause::Open:
format = _("Audacity failed to open a file at %s.\n");
break;
case Cause::Read:
format = _("Audacity failed to read from a file at %s.\n");
break;
case Cause::Write:
format = _(
"Audacity failed to write to a file at %s.\nAttempt this operation again after removing unnecessary files.\nOne way to do that is with the Discard buttons in the History dialog.\nSee the View menu.");
break;
case Cause::Rename:
format = _(
"Audacity successfully wrote the file %s but failed to rename it as %s.");
default:
break;
}
return wxString::Format(
format, fileName.GetFullPath(), renameTarget.GetFullPath() );
}

46
src/FileException.h Normal file
View File

@@ -0,0 +1,46 @@
//
// FileException.h
//
//
// Created by Paul Licameli on 11/22/16.
//
//
#ifndef __AUDACITY_FILE_EXCEPTION__
#define __AUDACITY_FILE_EXCEPTION__
#include "AudacityException.h"
#include <wx/filename.h>
class FileException /* not final */ : public MessageBoxException
{
public:
enum class Cause { Open, Read, Write, Rename };
explicit FileException
( Cause cause_, const wxFileName &fileName_,
const wxString &caption = wxString{},
const wxFileName &renameTarget_ = {})
: MessageBoxException{ caption }
, fileName{ fileName_ }, cause{ cause_ }, renameTarget{ renameTarget_ }
{}
FileException(FileException&& that)
: MessageBoxException(std::move(that))
{}
~FileException() override;
protected:
std::unique_ptr< AudacityException > Move() override;
// Format a default, internationalized error message for this exception.
wxString ErrorMessage() const override;
public:
Cause cause;
wxFileName fileName;
wxFileName renameTarget;
};
#endif

View File

@@ -133,6 +133,8 @@ audacity_SOURCES = \
FFmpeg.h \
FFT.cpp \
FFT.h \
FileException.cpp \
FileException.h \
FileIO.cpp \
FileIO.h \
FileNames.cpp \