0

Here's my code snippet:

try 
{
    if ( query.exec(query_str) == false ) {
    err_desc = query.lastError().text().toStdString();
    return RET_FAIL;
    }
}
catch(QSqlError &e)
{   
    handleError(e);
}

I set a breakpoint inside handleError, but it seems this breakpoint was never reached when there is an error, with err_desc the following value:

MySQL server has gone away QMYSQL: unable to execute query

Why does it fail to catch the error ?

CDT
  • 10,165
  • 18
  • 66
  • 97

2 Answers2

2

I suspect you are not getting an exception when the server has gone away. There are other posts on handling this

Community
  • 1
  • 1
doctorlove
  • 18,872
  • 2
  • 46
  • 62
2

Because there's no error to catch.

If the query fails it return false and set a QSqlError, accessible via QSqlQuery::lastError(), but it doesn't raise an exception.

if ( query.exec(query_str) == false ) {
    err_desc = query.lastError().text().toStdString();
    handleError(query.lastError());
    return RET_FAIL;
}
asclepix
  • 7,971
  • 3
  • 31
  • 41