1
0
mirror of https://github.com/cookiengineer/audacity synced 2026-03-11 08:56:03 +01:00

Strong exception safety in all uses of XMLFileWriter...

... Strong, meaning that the file at the specified path is created or modified
only if all write operations complete without exceptions, barring one very
unlikely possibility that a final file rename fails, but even in that case the
output is successfully written to some path.

This commit does not add throws, but changes the type thrown to a subclass of
AudacityException, so that GuardedCall will cause the user to see an error
dialog in all cases.

Duplicated logic for making temporary files and backups is now all in one
place, the class XMLWriter.

There may be more new GuardedCalls than necessary -- the catch-all for the
event loop, AudacityApp::OnExceptionInMainLoop, might be trusted instead in
some cases --  but they are sufficient.
This commit is contained in:
Paul Licameli
2016-12-01 20:40:05 -05:00
parent b81cdee7e3
commit 3bb04245c5
12 changed files with 323 additions and 425 deletions

View File

@@ -376,20 +376,11 @@ void KeyConfigPrefs::OnExport(wxCommandEvent & WXUNUSED(event))
gPrefs->Write(wxT("/DefaultExportPath"), path);
gPrefs->Flush();
XMLFileWriter prefFile;
try
{
prefFile.Open(file, wxT("wb"));
GuardedCall< void >( [&] {
XMLFileWriter prefFile{ file, _("Error Exporting Keyboard Shortcuts") };
mManager->WriteXML(prefFile);
prefFile.Close();
}
catch (const XMLFileWriterException &)
{
wxMessageBox(_("Couldn't write to file: ") + file,
_("Error Exporting Keyboard Shortcuts"),
wxOK | wxCENTRE, this);
}
prefFile.Commit();
} );
}
void KeyConfigPrefs::OnDefaults(wxCommandEvent & WXUNUSED(event))
@@ -957,20 +948,11 @@ void KeyConfigPrefs::OnExport(wxCommandEvent & WXUNUSED(event))
gPrefs->Write(wxT("/DefaultExportPath"), path);
gPrefs->Flush();
XMLFileWriter prefFile;
try
{
prefFile.Open(file, wxT("wb"));
GuardedCall< void >( [&] {
XMLFileWriter prefFile{ file, _("Error Exporting Keyboard Shortcuts") };
mManager->WriteXML(prefFile);
prefFile.Close();
}
catch (const XMLFileWriterException &)
{
wxMessageBox(_("Couldn't write to file: ") + file,
_("Error Exporting Keyboard Shortcuts"),
wxOK | wxCENTRE, this);
}
prefFile.Commit();
} );
}
void KeyConfigPrefs::OnDefaults(wxCommandEvent & WXUNUSED(event))