Subclassing QException
-
Hi,
I want to subclass QException in order to handle QSqlError. My current exception handling code is the following :
try { query.exec(queryString); throw query.lastError().text(); } catch (QString &e) { if (!e.isEmpty()) { bool ret = QERMessageBox(e); if (ret = true) // Code } }
I thought of reimplanting QException like this :
class SqlException: public QException { public: SqlException(QString const& text=" ") throw() :m_phrase(text) {} virtual const QChar* what() const throw() { return m_text.data(); } void SqlException::raise() const { SqlException e = *this; throw e; } SqlException *SqlException::clone() const { return new SqlException(*this); } virtual ~Erreur() throw() {} private: string m_text; \\ QSqlQuery.lastError().text(); };
However I don't understand the use of the raise() and the clone() function. Also, I get the following error from the what function when compiling : return cannot convert from const QChat * to const char *.
-
Hi,
Raise is to actually throw the exception and clone is to create a copy of your exception. As for your other error m_text is a string and not a QString.