I don't catch exception in Qt



  • I've encountered a big surprise for me.
    My program doesn't catch any exception (in particully in main function ) when qt libraries have been included.
    I googled this problem and didn't find an answer.
    Please explain me:

    1. Why this happens ?
    2. How to bypass this ? I use a combination of libraries in software development (stl, boost, opencv) and i cant develop software, applying ONLY QT.
      Details:
      QT version - 5.2
      Mingw 4.8 and 6.02

    .pro file

    #-------------------------------------------------
    #
    # Project created by QtCreator 2018-04-28T23:53:47
    #
    #-------------------------------------------------
     
    QT       += core gui
     
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    TARGET = qt_eception
    TEMPLATE = app
     
     
    SOURCES += main.cpp
     
    HEADERS  +=
     
    FORMS    +=
    

    main.cpp

    #include <QApplication>
     
    #undef main
    int main(int argc, char *argv[])
    {
     
        try
        {
            QApplication a(argc, argv);
            throw "ex";
        }
        catch(...)
        {
            // Do Nothing
        }
        return 0;
    }
    

    ![alt text](0_1524989131978_bug.png image url)


  • Lifetime Qt Champion

    Hi
    Qt should not have any effect your your ability to use exceptions.
    Tried your sample on win 10 , vs 2015 compiler and it works.

    alt text



  • @mrjj I don't have any problem with exception, if i don't include and don't apply Qt library. I use Qt creator 3.0.0 and windows 7. Can you advise me, where start to research this problem ?


  • Lifetime Qt Champion

    @Petin
    When you dont "apply Qt library. " can it be its other compiler or
    setting that is being used ?
    What compiler are you using ?


  • Moderators

    @Petin, does your program run correctly if you don't throw an exception?


Log in to reply