Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Subclassing QException
Forum Updated to NodeBB v4.3 + New Features

Subclassing QException

Scheduled Pinned Locked Moved General and Desktop
qexception
2 Posts 2 Posters 2.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    samuelpdrouin
    wrote on last edited by samuelpdrouin
    #1

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

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved