diff options
author | Christian Kandeler <christian.kandeler@digia.com> | 2014-01-10 13:07:03 +0100 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@digia.com> | 2014-01-10 17:03:35 +0100 |
commit | 789877ceaac15af1b0a6644a8c14422787a898dc (patch) | |
tree | 0e29d36638fa6559c90a1062c3e157aa927614a5 | |
parent | 921cbe22c4d3e82b484aa225f42292d867fd6e7e (diff) |
Do not leak exceptions from the Profile class.
This is public API.
Change-Id: I37cfd018e350a3ff4cecba34af42bf23a8aaf0fd
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
-rw-r--r-- | src/lib/tools/profile.cpp | 24 | ||||
-rw-r--r-- | src/lib/tools/profile.h | 6 | ||||
-rw-r--r-- | src/lib/tools/setupprojectparameters.cpp | 11 |
3 files changed, 30 insertions, 11 deletions
diff --git a/src/lib/tools/profile.cpp b/src/lib/tools/profile.cpp index cb3186ae4..bef07eedb 100644 --- a/src/lib/tools/profile.cpp +++ b/src/lib/tools/profile.cpp @@ -65,9 +65,15 @@ bool Profile::exists() const /*! * \brief Returns the value for property \c key in this profile. */ -QVariant Profile::value(const QString &key, const QVariant &defaultValue) const -{ - return possiblyInheritedValue(key, defaultValue, QStringList()); +QVariant Profile::value(const QString &key, const QVariant &defaultValue, ErrorInfo *error) const +{ + try { + return possiblyInheritedValue(key, defaultValue, QStringList()); + } catch (const ErrorInfo &e) { + if (error) + *error = e; + return QVariant(); + } } /*! @@ -103,9 +109,15 @@ QString Profile::name() const * If and only if selection is Profile::KeySelectionRecursive, this will also list keys defined * in base profiles. */ -QStringList Profile::allKeys(KeySelection selection) const -{ - return allKeysInternal(selection, QStringList()); +QStringList Profile::allKeys(KeySelection selection, ErrorInfo *error) const +{ + try { + return allKeysInternal(selection, QStringList()); + } catch (const ErrorInfo &e) { + if (error) + *error = e; + return QStringList(); + } } /*! diff --git a/src/lib/tools/profile.h b/src/lib/tools/profile.h index c3b0bbfe8..740f23931 100644 --- a/src/lib/tools/profile.h +++ b/src/lib/tools/profile.h @@ -36,6 +36,7 @@ #include <QVariant> namespace qbs { +class ErrorInfo; class Settings; class QBS_EXPORT Profile @@ -44,7 +45,8 @@ public: explicit Profile(const QString &name, Settings *settings); bool exists() const; - QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const; + QVariant value(const QString &key, const QVariant &defaultValue = QVariant(), + ErrorInfo *error = 0) const; void setValue(const QString &key, const QVariant &value); void remove(const QString &key); @@ -57,7 +59,7 @@ public: void removeProfile(); enum KeySelection { KeySelectionRecursive, KeySelectionNonRecursive }; - QStringList allKeys(KeySelection selection) const; + QStringList allKeys(KeySelection selection, ErrorInfo *error = 0) const; static QString cleanName(const QString &name); diff --git a/src/lib/tools/setupprojectparameters.cpp b/src/lib/tools/setupprojectparameters.cpp index c3b00f3c4..9f6c07cb8 100644 --- a/src/lib/tools/setupprojectparameters.cpp +++ b/src/lib/tools/setupprojectparameters.cpp @@ -294,14 +294,19 @@ ErrorInfo SetupProjectParameters::expandBuildConfiguration(Settings *settings) // (2) const Profile profile(profileName, settings); - const QStringList profileKeys = profile.allKeys(Profile::KeySelectionRecursive); + const QStringList profileKeys = profile.allKeys(Profile::KeySelectionRecursive, &err); + if (err.hasError()) + return err; if (profileKeys.isEmpty()) { err.append(Internal::Tr::tr("Unknown or empty profile '%1'.").arg(profileName)); return err; } foreach (const QString &profileKey, profileKeys) { - if (!expandedConfig.contains(profileKey)) - expandedConfig.insert(profileKey, profile.value(profileKey)); + if (!expandedConfig.contains(profileKey)) { + expandedConfig.insert(profileKey, profile.value(profileKey, QVariant(), &err)); + if (err.hasError()) + return err; + } } if (d->buildConfiguration != expandedConfig) { |