-5

I have a problem in my qt project, when an exception is thrown my windows crash and close, why? Where is the problem? I do not understand.

   class MyException:public std::exception{
    private:
        QMessageBox* mex;
    public:
        MyException(QString);

    };

    class err_parser_binary:public MyException{
    public:
        err_parser_binary(QString);
    };

MyException::MyException(QString d):mex(new QMessageBox()){
    mex->setText("Error");
    mex->setDetailedText(d);
    mex->button(QMessageBox::Ok);
    mex->show();
}

err_parser_binary::err_parser_binary(QString detail): MyException(detail){

}

QString binary_controller::calcolaop1op2(QString x, QString y, QString op) try{
...............
    Binary* pb=new Binary(op2);

..................
}
catch (err_parser_binary) {}

Binary::Binary(std::string str){
......
        throw err_parser_binary("only 1 o 0");
......
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Damien
  • 11

1 Answers1

0

From what I've read, Qt is not really exception safe. Take a look at this page. At the top, it says:

Preliminary warning: Exception safety is not feature complete! Common cases should work, but classes might still leak or even crash.

Qt itself will not throw exceptions. Instead, error codes are used. In addition, some classes have user visible error messages, for example QIODevice::errorString() or QSqlQuery::lastError(). This has historical and practical reasons - turning on exceptions can increase the library size by over 20%.

You should just use error codes and/or error messages instead.

Mitch
  • 23,716
  • 9
  • 83
  • 122
  • Eh, just saw https://stackoverflow.com/questions/3130734/exception-safety-in-qt after I posted this. – Mitch Feb 07 '18 at 15:50