Catch C++ exceptions by const reference

Fixes #2277
This commit is contained in:
Charles Milette
2018-05-19 19:18:26 -04:00
parent b9fd381eee
commit 72c0002b45
22 changed files with 36 additions and 38 deletions

View File

@ -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;

View File

@ -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;

View File

@ -123,7 +123,7 @@ T ensureIsType(const QJsonValue &value, const T default_ = T(), const QString &w
{
return requireIsType<T>(value, what);
}
catch (JsonException &)
catch (JsonException)
{
return default_;
}

View File

@ -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.

View File

@ -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();
}

View File

@ -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<LaunchProfile> ComponentList::getProfile() const
}
d->m_profile = profile;
}
catch (Exception & error)
catch (const Exception &error)
{
qWarning() << "Couldn't apply profile patches because: " << error.cause();
}

View File

@ -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());
}

View File

@ -263,13 +263,13 @@ static QString read_string (nbt::value& parent, const char * name, const QString
auto & tag_str = namedValue.as<nbt::tag_string>();
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<nbt::tag_long>();
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;

View File

@ -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();

View File

@ -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:";

View File

@ -266,7 +266,7 @@ void HttpMetaCache::SaveNow()
{
FS::write(m_index_file, doc.toJson());
}
catch (Exception & e)
catch (const Exception &e)
{
qWarning() << e.what();
}

View File

@ -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;

View File

@ -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;