Audacity 3.2.0
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 class  Cause { Open , Read , Write , 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
virtual void DelayedHandlerAction ()=0
 Action to do in the main thread at idle time of the event loop. More...

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 &)
virtual TranslatableString ErrorMessage () const =0
 Format the error message for this exception. More...
virtual wxString ErrorHelpUrl () const
- 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 class 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 {}
@ Internal
Indicates internal failure from Audacity.
wxFileName renameTarget
Definition: FileException.h:64
wxFileName fileName
Definition: FileException.h:63
Abstract AudacityException subclass displays a message, specified by further subclass.
TranslatableString caption
Stored caption.

◆ 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 }
48 {}
MessageBoxException(ExceptionType exceptionType, const TranslatableString &caption)
If default-constructed with empty caption, it makes no message box.

◆ ~FileException()

FileException::~FileException ( )

Definition at line 15 of file FileException.cpp.


Member Function Documentation

◆ ErrorHelpUrl()

wxString FileException::ErrorHelpUrl ( ) const

Reimplemented from MessageBoxException.

Definition at line 42 of file FileException.cpp.

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 "";
@ Write
most important to detect when storage space is exhausted
@ Rename
involves two filenames

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.

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 =
33XO("Audacity successfully wrote a file in %s but failed to rename it as %s.");
34 default:
35 break;
36 }
38 return format.Format(
static TranslatableString WriteFailureMessage(const wxFileName &fileName)
Holds a msgid for the translation catalog; may also bind format arguments.
FILES_API wxString AbbreviatePath(const wxFileName &fileName)
Give enough of the path to identify the device. (On Windows, drive letter plus ':')

References FileNames::AbbreviatePath(), cause, fileName, anonymous_namespace{ExportPCM.cpp}::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.

62 return XO("Audacity failed to write to a file.\n"
63 "Perhaps %s is not writable or the disk is full."

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(), and ErrorMessage().

◆ 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: