fix(GODT-2449): fix bug in Bridge-GUI's Exception::what().

Cherry picked from release/perth_narrows (1d426e6)
This commit is contained in:
Xavier Michelon
2023-03-07 08:52:57 +01:00
parent 9058544f5c
commit 21ffde316d
2 changed files with 10 additions and 6 deletions

View File

@ -26,9 +26,10 @@ namespace bridgepp {
/// \param[in] what A description of the exception.
/// \param[in] details The optional details for the exception.
//****************************************************************************************************************************************************
Exception::Exception(QString what, QString details) noexcept
Exception::Exception(QString qwhat, QString details) noexcept
: std::exception()
, what_(std::move(what))
, qwhat_(std::move(qwhat))
, what_(qwhat_.toLocal8Bit())
, details_(std::move(details)) {
}
@ -38,6 +39,7 @@ Exception::Exception(QString what, QString details) noexcept
//****************************************************************************************************************************************************
Exception::Exception(Exception const &ref) noexcept
: std::exception(ref)
, qwhat_(ref.qwhat_)
, what_(ref.what_)
, details_(ref.details_) {
}
@ -48,6 +50,7 @@ Exception::Exception(Exception const &ref) noexcept
//****************************************************************************************************************************************************
Exception::Exception(Exception &&ref) noexcept
: std::exception(ref)
, qwhat_(ref.qwhat_)
, what_(ref.what_)
, details_(ref.details_) {
}
@ -57,7 +60,7 @@ Exception::Exception(Exception &&ref) noexcept
/// \return a string describing the exception
//****************************************************************************************************************************************************
QString Exception::qwhat() const noexcept {
return what_;
return qwhat_;
}
@ -65,7 +68,7 @@ QString Exception::qwhat() const noexcept {
/// \return A pointer to the description string of the exception.
//****************************************************************************************************************************************************
const char *Exception::what() const noexcept {
return what_.toLocal8Bit().constData();
return what_.constData();
}

View File

@ -31,7 +31,7 @@ namespace bridgepp {
//****************************************************************************************************************************************************
class Exception : public std::exception {
public: // member functions
explicit Exception(QString what = QString(), QString details = QString()) noexcept; ///< Constructor
explicit Exception(QString qwhat = QString(), QString details = QString()) noexcept; ///< Constructor
Exception(Exception const &ref) noexcept; ///< copy constructor
Exception(Exception &&ref) noexcept; ///< copy constructor
Exception &operator=(Exception const &) = delete; ///< Disabled assignment operator
@ -42,7 +42,8 @@ public: // member functions
QString details() const noexcept; ///< Return the details for the exception
private: // data members
QString const what_; ///< The description of the exception.
QString const qwhat_; ///< The description of the exception.
QByteArray const what_; ///< The c-string version of the qwhat message. Stored as a QByteArray for automatic lifetime management.
QString const details_; ///< The optional details for the exception.
};