Beside the destructor which might be removed, since it is already virtual and noexcept in std::exception:
- Code: Select all
virtual ~sql_error() throw() { ; }
The method what is implemented like this:
- Code: Select all
virtual const char * what() const throw()
{ return (m_error.isValid() ? qPrintable(m_error.text()) : ""); }
With the qPrintable macro expansion:
- Code: Select all
#ifndef qPrintable
# define qPrintable(string) QString(string).toLocal8Bit().constData()
#endif
This becomes:
- Code: Select all
virtual const char * what() const throw()
{ return (m_error.isValid() ? QString(m_error.text()).toLocal8Bit().constData() : ""); }
This means that a new QString object gets allocated and toLocal8Bit() causes the creation of a new QByteArray. But now we return its constData() which may be used later when the byte array has already been deallocated.
According to me we would need to introduce a QByteArray buffer (e.g. m_errorMessage) as the exception member, which lives as long as the exception and remodel what() like this:
- Code: Select all
virtual const char * what() const throw()
{ return (m_error.isValid() ? m_errorMessage.constData() : ""); }