From 72c0002b45215466e06cd901fe95d9493d659ab2 Mon Sep 17 00:00:00 2001 From: Charles Milette Date: Sat, 19 May 2018 19:18:26 -0400 Subject: Catch C++ exceptions by const reference Fixes #2277 --- api/logic/FolderInstanceProvider.cpp | 4 ++-- api/logic/InstanceImportTask.cpp | 2 +- api/logic/Json.h | 2 +- api/logic/meta/BaseEntity.cpp | 4 ++-- api/logic/minecraft/Component.cpp | 2 +- api/logic/minecraft/ComponentList.cpp | 4 ++-- api/logic/minecraft/ProfileUtils.cpp | 4 ++-- api/logic/minecraft/World.cpp | 10 +++++----- api/logic/minecraft/forge/ForgeXzDownload.cpp | 2 +- api/logic/modplatform/flame/FileResolvingTask.cpp | 2 +- api/logic/net/HttpMetaCache.cpp | 2 +- api/logic/settings/INIFile.cpp | 2 +- api/logic/translations/TranslationsModel.cpp | 2 +- application/MultiMC.cpp | 2 +- application/UpdateController.cpp | 2 +- application/dialogs/ExportInstanceDialog.cpp | 2 +- application/dialogs/UpdateDialog.cpp | 2 +- application/pages/instance/ServersPage.cpp | 4 ++-- application/pages/instance/VersionPage.cpp | 6 +++--- application/themes/CustomTheme.cpp | 8 ++++---- libraries/classparser/src/classparser.cpp | 4 +--- libraries/pack200/anti200.cpp | 2 +- 22 files changed, 36 insertions(+), 38 deletions(-) diff --git a/api/logic/FolderInstanceProvider.cpp b/api/logic/FolderInstanceProvider.cpp index 69ba6c82..04d5a66b 100644 --- a/api/logic/FolderInstanceProvider.cpp +++ b/api/logic/FolderInstanceProvider.cpp @@ -160,7 +160,7 @@ void FolderInstanceProvider::saveGroupList() { FS::write(groupFileName, doc.toJson()); } - catch(FS::FileSystemException & e) + catch (const FS::FileSystemException &e) { qCritical() << "Failed to write instance group file :" << e.cause(); } @@ -181,7 +181,7 @@ void FolderInstanceProvider::loadGroupList() { jsonData = FS::read(groupFileName); } - catch (FS::FileSystemException & e) + catch (const FS::FileSystemException &e) { qCritical() << "Failed to read instance group file :" << e.cause(); return; diff --git a/api/logic/InstanceImportTask.cpp b/api/logic/InstanceImportTask.cpp index b5375cbc..45037908 100644 --- a/api/logic/InstanceImportTask.cpp +++ b/api/logic/InstanceImportTask.cpp @@ -188,7 +188,7 @@ void InstanceImportTask::processFlame() Flame::loadManifest(pack, configPath); QFile::remove(configPath); } - catch (JSONValidationError & e) + catch (const JSONValidationError &e) { emitFailed(tr("Could not understand pack manifest:\n") + e.cause()); return; diff --git a/api/logic/Json.h b/api/logic/Json.h index e59b25de..321007cd 100644 --- a/api/logic/Json.h +++ b/api/logic/Json.h @@ -123,7 +123,7 @@ T ensureIsType(const QJsonValue &value, const T default_ = T(), const QString &w { return requireIsType(value, what); } - catch (JsonException &) + catch (JsonException) { return default_; } diff --git a/api/logic/meta/BaseEntity.cpp b/api/logic/meta/BaseEntity.cpp index 5c2339cb..342f676c 100644 --- a/api/logic/meta/BaseEntity.cpp +++ b/api/logic/meta/BaseEntity.cpp @@ -56,7 +56,7 @@ public: /* methods */ m_entity->parse(Json::requireObject(Json::requireDocument(data, fname), fname)); return true; } - catch (Exception &e) + catch (const Exception &e) { qWarning() << "Unable to parse response:" << e.cause(); return false; @@ -90,7 +90,7 @@ bool Meta::BaseEntity::loadLocalFile() parse(Json::requireObject(Json::requireDocument(fname, fname), fname)); return true; } - catch (Exception &e) + catch (const Exception &e) { qDebug() << QString("Unable to parse file %1: %2").arg(fname, e.cause()); // just make sure it's gone and we never consider it again. diff --git a/api/logic/minecraft/Component.cpp b/api/logic/minecraft/Component.cpp index 50a2ae16..c6e41e65 100644 --- a/api/logic/minecraft/Component.cpp +++ b/api/logic/minecraft/Component.cpp @@ -323,7 +323,7 @@ bool Component::customize() m_metaVersion.reset(); emit dataChanged(); } - catch (Exception &error) + catch (const Exception &error) { qWarning() << "Version could not be loaded:" << error.cause(); } diff --git a/api/logic/minecraft/ComponentList.cpp b/api/logic/minecraft/ComponentList.cpp index a207e987..e373d499 100644 --- a/api/logic/minecraft/ComponentList.cpp +++ b/api/logic/minecraft/ComponentList.cpp @@ -195,7 +195,7 @@ static bool loadComponentList(ComponentList * parent, const QString & filename, container.append(componentFromJsonV1(parent, componentJsonPattern, obj)); } } - catch (JSONValidationError &err) + catch (const JSONValidationError &err) { qCritical() << "Couldn't parse" << componentsFile.fileName() << ": bad file format"; container.clear(); @@ -1150,7 +1150,7 @@ std::shared_ptr ComponentList::getProfile() const } d->m_profile = profile; } - catch (Exception & error) + catch (const Exception &error) { qWarning() << "Couldn't apply profile patches because: " << error.cause(); } diff --git a/api/logic/minecraft/ProfileUtils.cpp b/api/logic/minecraft/ProfileUtils.cpp index a6d2028d..2227e438 100644 --- a/api/logic/minecraft/ProfileUtils.cpp +++ b/api/logic/minecraft/ProfileUtils.cpp @@ -57,7 +57,7 @@ bool readOverrideOrders(QString path, PatchOrder &order) order.append(Json::requireString(item)); } } - catch (JSONValidationError &err) + catch (const JSONValidationError &err) { qCritical() << "Couldn't parse" << orderFile.fileName() << ": bad file format"; qWarning() << "Ignoring overriden order"; @@ -82,7 +82,7 @@ static VersionFilePtr guardedParseJson(const QJsonDocument & doc,const QString & { return OneSixVersionFormat::versionFileFromJson(doc, filepath, requireOrder); } - catch (Exception & e) + catch (const Exception &e) { return createErrorVersionFile(fileId, filepath, e.cause()); } diff --git a/api/logic/minecraft/World.cpp b/api/logic/minecraft/World.cpp index 68c0a5cc..227a9b75 100644 --- a/api/logic/minecraft/World.cpp +++ b/api/logic/minecraft/World.cpp @@ -263,13 +263,13 @@ static QString read_string (nbt::value& parent, const char * name, const QString auto & tag_str = namedValue.as(); return QString::fromStdString(tag_str.get()); } - catch(std::out_of_range e) + catch (const std::out_of_range &e) { // fallback for old world formats qWarning() << "String NBT tag" << name << "could not be found. Defaulting to" << fallback; return fallback; } - catch(std::bad_cast e) + catch (const std::bad_cast &e) { // type mismatch qWarning() << "NBT tag" << name << "could not be converted to string. Defaulting to" << fallback; @@ -289,13 +289,13 @@ static int64_t read_long (nbt::value& parent, const char * name, const int64_t & auto & tag_str = namedValue.as(); return tag_str.get(); } - catch(std::out_of_range e) + catch (const std::out_of_range &e) { // fallback for old world formats qWarning() << "Long NBT tag" << name << "could not be found. Defaulting to" << fallback; return fallback; } - catch(std::bad_cast e) + catch (const std::bad_cast &e) { // type mismatch qWarning() << "NBT tag" << name << "could not be converted to long. Defaulting to" << fallback; @@ -338,7 +338,7 @@ void World::loadFromLevelDat(QByteArray data) qDebug() << "Last Played:" << m_lastPlayed.toString(); qDebug() << "Seed:" << m_randomSeed; } - catch (nbt::io::input_error e) + catch (const nbt::io::input_error &e) { qWarning() << "Unable to load" << m_folderName << ":" << e.what(); is_valid = false; diff --git a/api/logic/minecraft/forge/ForgeXzDownload.cpp b/api/logic/minecraft/forge/ForgeXzDownload.cpp index a05d0f8d..4d82a58a 100644 --- a/api/logic/minecraft/forge/ForgeXzDownload.cpp +++ b/api/logic/minecraft/forge/ForgeXzDownload.cpp @@ -345,7 +345,7 @@ void ForgeXzDownload::decompressAndInstall() // NOTE: this takes ownership of both FILE pointers. That's why we duplicate them above. unpack_200(file_in, file_out); } - catch (std::runtime_error &err) + catch (const std::runtime_error &err) { m_status = Job_Failed; qCritical() << "Error unpacking " << pack200_file.fileName() << " : " << err.what(); diff --git a/api/logic/modplatform/flame/FileResolvingTask.cpp b/api/logic/modplatform/flame/FileResolvingTask.cpp index efc73621..5eb82458 100644 --- a/api/logic/modplatform/flame/FileResolvingTask.cpp +++ b/api/logic/modplatform/flame/FileResolvingTask.cpp @@ -95,7 +95,7 @@ void Flame::FileResolvingTask::netJobFinished() } out.resolved = true; } - catch(JSONValidationError & e) + catch (const JSONValidationError &e) { auto & out = m_toProcess.files[index]; qCritical() << "Resolving of" << out.projectId << out.fileId << "failed because of a parsing error:"; diff --git a/api/logic/net/HttpMetaCache.cpp b/api/logic/net/HttpMetaCache.cpp index ebcb0a27..95906d2c 100644 --- a/api/logic/net/HttpMetaCache.cpp +++ b/api/logic/net/HttpMetaCache.cpp @@ -266,7 +266,7 @@ void HttpMetaCache::SaveNow() { FS::write(m_index_file, doc.toJson()); } - catch (Exception & e) + catch (const Exception &e) { qWarning() << e.what(); } diff --git a/api/logic/settings/INIFile.cpp b/api/logic/settings/INIFile.cpp index 9e97f861..67c6cf29 100644 --- a/api/logic/settings/INIFile.cpp +++ b/api/logic/settings/INIFile.cpp @@ -90,7 +90,7 @@ bool INIFile::saveFile(QString fileName) { FS::write(fileName, outArray); } - catch (Exception & e) + catch (const Exception &e) { qCritical() << e.what(); return false; diff --git a/api/logic/translations/TranslationsModel.cpp b/api/logic/translations/TranslationsModel.cpp index 868aa98f..18625ee5 100644 --- a/api/logic/translations/TranslationsModel.cpp +++ b/api/logic/translations/TranslationsModel.cpp @@ -225,7 +225,7 @@ void TranslationsModel::loadLocalIndex() { data = FS::read(d->m_dir.absoluteFilePath("index")); } - catch (Exception &e) + catch (const Exception &e) { qCritical() << "Translations Download Failed: index file not readable"; return; diff --git a/application/MultiMC.cpp b/application/MultiMC.cpp index 4236fbcf..e7e6d337 100644 --- a/application/MultiMC.cpp +++ b/application/MultiMC.cpp @@ -174,7 +174,7 @@ MultiMC::MultiMC(int &argc, char **argv) : QApplication(argc, argv) { args = parser.parse(arguments()); } - catch (ParsingError e) + catch (const ParsingError &e) { std::cerr << "CommandLineError: " << e.what() << std::endl; std::cerr << "Try '%1 -h' to get help on MultiMC's command line parameters." diff --git a/application/UpdateController.cpp b/application/UpdateController.cpp index 8df5b3fc..733e365f 100644 --- a/application/UpdateController.cpp +++ b/application/UpdateController.cpp @@ -331,7 +331,7 @@ void UpdateController::installUpdates() break; } } - catch(Exception e) + catch (const Exception &e) { qWarning() << "Couldn't read the" << liveCheckFile << "file!"; startFailed = true; diff --git a/application/dialogs/ExportInstanceDialog.cpp b/application/dialogs/ExportInstanceDialog.cpp index 0e19b758..9029ca50 100644 --- a/application/dialogs/ExportInstanceDialog.cpp +++ b/application/dialogs/ExportInstanceDialog.cpp @@ -479,7 +479,7 @@ void ExportInstanceDialog::savePackIgnore() { FS::write(filename, data); } - catch (Exception & e) + catch (const Exception &e) { qWarning() << e.cause(); } diff --git a/application/dialogs/UpdateDialog.cpp b/application/dialogs/UpdateDialog.cpp index 30c7173d..754338c6 100644 --- a/application/dialogs/UpdateDialog.cpp +++ b/application/dialogs/UpdateDialog.cpp @@ -135,7 +135,7 @@ QString reprocessCommits(QByteArray json) result += QObject::tr("

You can look at the changes on github.

").arg(diff_url); return result; } - catch (JSONValidationError & e) + catch (const JSONValidationError &e) { qWarning() << "Got an unparseable commit log from github:" << e.what(); qDebug() << json; diff --git a/application/pages/instance/ServersPage.cpp b/application/pages/instance/ServersPage.cpp index f7ddc7da..1612ce09 100644 --- a/application/pages/instance/ServersPage.cpp +++ b/application/pages/instance/ServersPage.cpp @@ -109,7 +109,7 @@ static std::unique_ptr parseServersDat(const QString& filena return std::move(pair.second); } - catch(...) + catch (...) { return nullptr; } @@ -125,7 +125,7 @@ static bool serializeServerDat(const QString& filename, nbt::tag_compound * leve FS::write(filename, val); return true; } - catch(...) + catch (...) { return false; } diff --git a/application/pages/instance/VersionPage.cpp b/application/pages/instance/VersionPage.cpp index 00ae0a7e..981cbd8c 100644 --- a/application/pages/instance/VersionPage.cpp +++ b/application/pages/instance/VersionPage.cpp @@ -200,7 +200,7 @@ bool VersionPage::reloadComponentList() m_profile->reload(Net::Mode::Online); return true; } - catch (Exception &e) + catch (const Exception &e) { QMessageBox::critical(this, tr("Error"), e.cause()); return false; @@ -269,7 +269,7 @@ void VersionPage::on_moveUpBtn_clicked() { m_profile->move(currentRow(), ComponentList::MoveUp); } - catch (Exception &e) + catch (const Exception &e) { QMessageBox::critical(this, tr("Error"), e.cause()); } @@ -282,7 +282,7 @@ void VersionPage::on_moveDownBtn_clicked() { m_profile->move(currentRow(), ComponentList::MoveDown); } - catch (Exception &e) + catch (const Exception &e) { QMessageBox::critical(this, tr("Error"), e.cause()); } diff --git a/application/themes/CustomTheme.cpp b/application/themes/CustomTheme.cpp index a6c7bf8c..28e8c5c0 100644 --- a/application/themes/CustomTheme.cpp +++ b/application/themes/CustomTheme.cpp @@ -66,7 +66,7 @@ static bool readThemeJson(const QString &path, QPalette &palette, double &fadeAm fadeAmount = Json::ensureDouble(colorsRoot, "fadeAmount", 0.5, "fade amount"); } - catch(Exception e) + catch (const Exception &e) { qWarning() << "Couldn't load theme json: " << e.cause(); return false; @@ -117,7 +117,7 @@ static bool writeThemeJson(const QString &path, const QPalette &palette, double Json::write(rootObj, path); return true; } - catch (Exception e) + catch (const Exception &e) { qWarning() << "Failed to write theme json to" << path; return false; @@ -171,7 +171,7 @@ CustomTheme::CustomTheme(ITheme* baseTheme, QString folder) // TODO: validate css? m_styleSheet = QString::fromUtf8(FS::read(cssFilePath)); } - catch(Exception e) + catch (const Exception &e) { qWarning() << "Couldn't load css:" << e.cause() << "from" << cssFilePath; m_styleSheet = baseTheme->appStyleSheet(); @@ -185,7 +185,7 @@ CustomTheme::CustomTheme(ITheme* baseTheme, QString folder) { FS::write(cssFilePath, m_styleSheet.toUtf8()); } - catch(Exception e) + catch (const Exception &e) { qWarning() << "Couldn't write css:" << e.cause() << "to" << cssFilePath; } diff --git a/libraries/classparser/src/classparser.cpp b/libraries/classparser/src/classparser.cpp index 8837781f..bf5cc039 100644 --- a/libraries/classparser/src/classparser.cpp +++ b/libraries/classparser/src/classparser.cpp @@ -70,9 +70,7 @@ QString GetMinecraftJarVersion(QString jarName) } } } - catch (java::classfile_exception &) - { - } + catch (java::classfile_exception) { } // clean up delete[] classfile; diff --git a/libraries/pack200/anti200.cpp b/libraries/pack200/anti200.cpp index 944e80e5..0fa3d3e6 100644 --- a/libraries/pack200/anti200.cpp +++ b/libraries/pack200/anti200.cpp @@ -32,7 +32,7 @@ int main(int argc, char **argv) { unpack_200(input, output); } - catch (std::runtime_error &e) + catch (const std::runtime_error &e) { std::cerr << "Bad things happened: " << e.what() << std::endl; fclose(input); -- cgit v1.2.3