From 6052b5f9be5311e342609d74167dd1972ee35ba8 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Sun, 14 Feb 2016 04:35:05 -0500 Subject: [PATCH] Throw by value, catch by reference: don't use pointers... ... that's what the better books on C++ recommend. --- src/AutoRecovery.cpp | 3 +-- src/Legacy.cpp | 6 ++---- src/Project.cpp | 12 ++++-------- src/Tags.cpp | 6 ++---- src/effects/Equalization.cpp | 6 ++---- src/prefs/KeyConfigPrefs.cpp | 8 ++------ src/xml/XMLWriter.cpp | 8 ++++---- 7 files changed, 17 insertions(+), 32 deletions(-) diff --git a/src/AutoRecovery.cpp b/src/AutoRecovery.cpp index 296585cc5..7ff3ae20c 100644 --- a/src/AutoRecovery.cpp +++ b/src/AutoRecovery.cpp @@ -761,9 +761,8 @@ bool AutoSaveFile::Decode(const wxString & fileName) out.Open(tempName, wxT("wb")); opened = out.IsOpened(); } - catch (XMLFileWriterException* pException) + catch (const XMLFileWriterException&) { - delete pException; } if (!opened) diff --git a/src/Legacy.cpp b/src/Legacy.cpp index 0bdaea7a3..4aba449c6 100644 --- a/src/Legacy.cpp +++ b/src/Legacy.cpp @@ -314,9 +314,8 @@ bool ConvertLegacyProjectFile(wxFileName filename) { xmlFile.Open(name, wxT("wb")); } - catch (XMLFileWriterException* pException) + catch (const XMLFileWriterException&) { - delete pException; return false; } @@ -360,10 +359,9 @@ bool ConvertLegacyProjectFile(wxFileName filename) xmlFile.EndTag(wxT("audacityproject")); xmlFile.Close(); } - catch (XMLFileWriterException* pException) + catch (const XMLFileWriterException&) { // Error writing XML file (e.g. disk full) - delete pException; return false; } diff --git a/src/Project.cpp b/src/Project.cpp index 25adcdade..d1153148e 100644 --- a/src/Project.cpp +++ b/src/Project.cpp @@ -3523,15 +3523,13 @@ bool AudacityProject::Save(bool overwrite /* = true */ , saveFile.Close(); } - catch (XMLFileWriterException* pException) + catch (const XMLFileWriterException &exception) { wxMessageBox(wxString::Format( _("Couldn't write to file \"%s\": %s"), - mFileName.c_str(), pException->GetMessage().c_str()), + mFileName.c_str(), exception.GetMessage().c_str()), _("Error Saving Project"), wxICON_ERROR); - delete pException; - // When XMLWriter throws an exception, it tries to close it before, // so we can at least try to DELETE the incomplete file and move the // backup file over. @@ -4769,15 +4767,13 @@ void AudacityProject::AutoSave() buffer.Write(saveFile); saveFile.Close(); } - catch (XMLFileWriterException* pException) + catch (const XMLFileWriterException &exception) { wxMessageBox(wxString::Format( _("Couldn't write to file \"%s\": %s"), - (fn + wxT(".tmp")).c_str(), pException->GetMessage().c_str()), + (fn + wxT(".tmp")).c_str(), exception.GetMessage().c_str()), _("Error Writing Autosave File"), wxICON_ERROR, this); - delete pException; - return; } diff --git a/src/Tags.cpp b/src/Tags.cpp index 620c7e15e..2b5fb9ee6 100644 --- a/src/Tags.cpp +++ b/src/Tags.cpp @@ -1154,14 +1154,12 @@ void TagsEditor::OnSave(wxCommandEvent & WXUNUSED(event)) // Close the file writer.Close(); } - catch (XMLFileWriterException* pException) + catch (const XMLFileWriterException &exception) { wxMessageBox(wxString::Format( _("Couldn't write to file \"%s\": %s"), - fn.c_str(), pException->GetMessage().c_str()), + fn.c_str(), exception.GetMessage().c_str()), _("Error Saving Tags File"), wxICON_ERROR, this); - - delete pException; } } diff --git a/src/effects/Equalization.cpp b/src/effects/Equalization.cpp index 591f0d375..761c5e3ee 100644 --- a/src/effects/Equalization.cpp +++ b/src/effects/Equalization.cpp @@ -1500,14 +1500,12 @@ void EffectEqualization::SaveCurves(wxString fileName) // Close the file eqFile.Close(); } - catch (XMLFileWriterException* pException) + catch (const XMLFileWriterException &exception) { wxMessageBox(wxString::Format( _("Couldn't write to file \"%s\": %s"), - fn.GetFullPath().c_str(), pException->GetMessage().c_str()), + fn.GetFullPath().c_str(), exception.GetMessage().c_str()), _("Error Saving Equalization Curves"), wxICON_ERROR, mUIParent); - - delete pException; } } diff --git a/src/prefs/KeyConfigPrefs.cpp b/src/prefs/KeyConfigPrefs.cpp index 6da10858a..315c4e546 100644 --- a/src/prefs/KeyConfigPrefs.cpp +++ b/src/prefs/KeyConfigPrefs.cpp @@ -384,13 +384,11 @@ void KeyConfigPrefs::OnExport(wxCommandEvent & WXUNUSED(event)) mManager->WriteXML(prefFile); prefFile.Close(); } - catch (XMLFileWriterException* pException) + catch (const XMLFileWriterException &) { wxMessageBox(_("Couldn't write to file: ") + file, _("Error Exporting Keyboard Shortcuts"), wxOK | wxCENTRE, this); - - delete pException; } } @@ -967,13 +965,11 @@ void KeyConfigPrefs::OnExport(wxCommandEvent & WXUNUSED(event)) mManager->WriteXML(prefFile); prefFile.Close(); } - catch (XMLFileWriterException* pException) + catch (const XMLFileWriterException &) { wxMessageBox(_("Couldn't write to file: ") + file, _("Error Exporting Keyboard Shortcuts"), wxOK | wxCENTRE, this); - - delete pException; } } diff --git a/src/xml/XMLWriter.cpp b/src/xml/XMLWriter.cpp index bc8940c2a..b1ee83fa0 100644 --- a/src/xml/XMLWriter.cpp +++ b/src/xml/XMLWriter.cpp @@ -266,7 +266,7 @@ XMLFileWriter::~XMLFileWriter() void XMLFileWriter::Open(const wxString &name, const wxString &mode) { if (!wxFFile::Open(name, mode)) - throw new XMLFileWriterException(_("Error Opening File")); + throw XMLFileWriterException(_("Error Opening File")); } void XMLFileWriter::Close() @@ -287,12 +287,12 @@ void XMLFileWriter::CloseWithoutEndingTags() wxFFile::Close(); /* i18n-hint: 'flushing' means writing any remaining queued up changes * to disk that have not yet been written.*/ - throw new XMLFileWriterException(_("Error Flushing File")); + throw XMLFileWriterException(_("Error Flushing File")); } // Note that this should never fail if flushing worked. if (!wxFFile::Close()) - throw new XMLFileWriterException(_("Error Closing File")); + throw XMLFileWriterException(_("Error Closing File")); } void XMLFileWriter::Write(const wxString &data) @@ -302,7 +302,7 @@ void XMLFileWriter::Write(const wxString &data) // When writing fails, we try to close the file before throwing the // exception, so it can at least be deleted. wxFFile::Close(); - throw new XMLFileWriterException(_("Error Writing to File")); + throw XMLFileWriterException(_("Error Writing to File")); } }