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 &&) PROHIBITED
 ~FileException () override
- Public Member Functions inherited from AudacityException
 AudacityException ()
virtual ~AudacityException ()=0

Static Public Member Functions

static TranslatableString WriteFailureMessage (const wxFileName &fileName)

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 &&)=delete
 Don't allow moves of this class or subclasses. More...
AudacityExceptionoperator= (const AudacityException &)=delete
 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 16 of file FileException.cpp.

17 {
18 }

Member Function Documentation

◆ ErrorHelpUrl()

wxString FileException::ErrorHelpUrl ( ) const

Reimplemented from MessageBoxException.

Definition at line 43 of file FileException.cpp.

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

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 20 of file FileException.cpp.

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

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 61 of file FileException.cpp.

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

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

◆ 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
@ Write
most important to detect when storage space is exhausted
@ Read
#define XO(s)
Definition: Internat.h:31
wxFileName fileName
Definition: FileException.h:63
AUDACITY_DLL_API wxString AbbreviatePath(const wxFileName &fileName)
Give enough of the path to identify the device. (On Windows, drive letter plus ':')
@ Open
int format
Definition: ExportPCM.cpp:54
gPrefs Read(wxT("/GUI/VerticalZooming"), &bVZoom, false)
Abstract AudacityException subclass displays a message, specified by further subclass.
Definition: AudacityException.h:58
@ Internal
Indicates internal failure from Audacity.
static TranslatableString WriteFailureMessage(const wxFileName &fileName)
Definition: FileException.cpp:61
wxFileName renameTarget
Definition: FileException.h:64
TranslatableString caption
Stored caption.
Definition: AudacityException.h:77
MessageBoxException(ExceptionType exceptionType, const TranslatableString &caption)
If default-constructed with empty caption, it makes no message box.
Definition: AudacityException.cpp:26