Audacity  3.0.3
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | List of all members
FileException Class Reference

Thrown for failure of file or database operations in deeply nested places. More...

#include <FileException.h>

Inheritance diagram for FileException:
Collaboration diagram for FileException:

Public Types

enum  Cause { Cause::Open, Cause::Read, Cause::Write, Cause::Rename }
 Identifies file operation that failed. More...

Public Member Functions

 FileException (Cause cause_, const wxFileName &fileName_, const TranslatableString &caption=XO("File Error"), const wxFileName &renameTarget_={})
 FileException (const FileException &that)
FileExceptionoperator= (FileException &&)=delete
 ~FileException () override
- Public Member Functions inherited from AudacityException
 AudacityException ()
virtual ~AudacityException ()=0

Static Public Member Functions

static TranslatableString WriteFailureMessage (const wxFileName &fileName)
- Static Public Member Functions inherited from AudacityException
static void EnqueueAction (std::exception_ptr pException, std::function< void(AudacityException *)> delayedHandler)

Public Attributes

Cause cause
wxFileName fileName
wxFileName renameTarget

Protected Member Functions

TranslatableString ErrorMessage () const override
 Format an error message appropriate for the Cause. More...
wxString ErrorHelpUrl () const override
- Protected Member Functions inherited from MessageBoxException
 MessageBoxException (ExceptionType exceptionType, const TranslatableString &caption)
 If default-constructed with empty caption, it makes no message box. More...
 ~MessageBoxException () override
 MessageBoxException (const MessageBoxException &)
- Protected Member Functions inherited from AudacityException
 AudacityException (const AudacityException &)=default
 Make this protected to prevent slicing copies. More...
 AudacityException (AudacityException &&) PROHIBITED
 Don't allow moves of this class or subclasses. More...
AudacityExceptionoperator= (const AudacityException &) PROHIBITED
 Disallow assignment. More...

Additional Inherited Members

- Protected Attributes inherited from MessageBoxException
wxString helpUrl { "" }

Detailed Description

Thrown for failure of file or database operations in deeply nested places.

Definition at line 17 of file FileException.h.

Member Enumeration Documentation

◆ Cause

enum FileException::Cause

Identifies file operation that failed.


most important to detect when storage space is exhausted


involves two filenames

Definition at line 22 of file FileException.h.

22  {
23  Open,
24  Read,
25  Write,
26  Rename
27  };

Constructor & Destructor Documentation

◆ FileException() [1/2]

FileException::FileException ( Cause  cause_,
const wxFileName &  fileName_,
const TranslatableString caption = XO("File Error"),
const wxFileName &  renameTarget_ = {} 
cause_What kind of file operation failed
fileName_Which file suffered a failure
captionShown in message box frame, not the main message
renameTarget_A second file name, only for renaming failure

Definition at line 29 of file FileException.h.

33  {}
34  )
35  // DV: We consider a FileException to be internal for now.
36  // We used to have some odd cases related to the read-only folder in 3.0.0,
37  // so it is good to have a full picture here.
38  // In case we see too many - we will tweak this behavior in the next release.
40  , cause{ cause_ }, fileName{ fileName_ }, renameTarget{ renameTarget_ }
41  {}

◆ FileException() [2/2]

FileException::FileException ( const FileException that)

Definition at line 43 of file FileException.h.

44  : MessageBoxException( that )
45  , cause{ that.cause }
46  , fileName{ that.fileName }
47  , renameTarget{ that.renameTarget }
48  {}

References cause.

◆ ~FileException()

FileException::~FileException ( )

Definition at line 15 of file FileException.cpp.

16 {
17 }

Member Function Documentation

◆ ErrorHelpUrl()

wxString FileException::ErrorHelpUrl ( ) const

Reimplemented from MessageBoxException.

Definition at line 42 of file FileException.cpp.

43 {
44  switch (cause) {
45  case Cause::Open:
46  case Cause::Read:
47  return "Error:_Opening_or_reading_file";
48  break;
49  case Cause::Write:
50  case Cause::Rename:
51  return "Error:_Disk_full_or_not_writable";
52  default:
53  break;
54  }
56  return "";
57 }

References cause, Open, Read, Rename, and Write.

◆ ErrorMessage()

TranslatableString FileException::ErrorMessage ( ) const

Format an error message appropriate for the Cause.

Implements MessageBoxException.

Definition at line 19 of file FileException.cpp.

20 {
22  switch (cause) {
23  case Cause::Open:
24  format = XO("Audacity failed to open a file in %s.");
25  break;
26  case Cause::Read:
27  format = XO("Audacity failed to read from a file in %s.");
28  break;
29  case Cause::Write:
31  case Cause::Rename:
32  format =
33 XO("Audacity successfully wrote a file in %s but failed to rename it as %s.");
34  default:
35  break;
36  }
38  return format.Format(
40 }

References FileNames::AbbreviatePath(), cause, fileName, format, Open, Read, Rename, renameTarget, Write, WriteFailureMessage(), and XO.

Here is the call graph for this function:

◆ operator=()

FileException& FileException::operator= ( FileException &&  )

◆ WriteFailureMessage()

TranslatableString FileException::WriteFailureMessage ( const wxFileName &  fileName)

Definition at line 60 of file FileException.cpp.

61 {
62  return XO("Audacity failed to write to a file.\n"
63  "Perhaps %s is not writable or the disk is full.\n"
64  "For tips on freeing up space, click the help button."
66 }

References FileNames::AbbreviatePath(), fileName, and XO.

Referenced by ProjectFileManager::DoSave(), ErrorMessage(), ProjectFileManager::SaveCopy(), ProjectFileIO::SaveProject(), and ShowDiskFullExportErrorDialog().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ cause

Cause FileException::cause

Definition at line 62 of file FileException.h.

Referenced by ErrorHelpUrl(), ErrorMessage(), and FileException().

◆ fileName

wxFileName FileException::fileName

Definition at line 63 of file FileException.h.

Referenced by ErrorMessage(), and WriteFailureMessage().

◆ renameTarget

wxFileName FileException::renameTarget

Definition at line 64 of file FileException.h.

Referenced by ErrorMessage().

The documentation for this class was generated from the following files:
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
Cause cause
Definition: FileException.h:62
@ Rename
involves two filenames
FILES_API wxString AbbreviatePath(const wxFileName &fileName)
Give enough of the path to identify the device. (On Windows, drive letter plus ':')
@ Write
most important to detect when storage space is exhausted
@ Read
#define XO(s)
Definition: Internat.h:31
wxFileName fileName
Definition: FileException.h:63
@ Open
int format
Definition: ExportPCM.cpp:56
gPrefs Read(wxT("/GUI/VerticalZooming"), &bVZoom, false)
Abstract AudacityException subclass displays a message, specified by further subclass.
Definition: AudacityException.h:62
@ Internal
Indicates internal failure from Audacity.
static TranslatableString WriteFailureMessage(const wxFileName &fileName)
Definition: FileException.cpp:60
wxFileName renameTarget
Definition: FileException.h:64
TranslatableString caption
Stored caption.
Definition: AudacityException.h:81
MessageBoxException(ExceptionType exceptionType, const TranslatableString &caption)
If default-constructed with empty caption, it makes no message box.
Definition: AudacityException.cpp:39