Results 1 to 2 of 2

Thread: I don't catch exception in Qt

  1. #1
    Join Date
    Mar 2014
    Posts
    12
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default 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
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2018-04-28T23:53:47
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core gui
    8.  
    9. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    10. TARGET = qt_eception
    11. TEMPLATE = app
    12.  
    13.  
    14. SOURCES += main.cpp
    15.  
    16. HEADERS +=
    17.  
    18. FORMS +=
    To copy to clipboard, switch view to plain text mode 
    main.cpp
    Qt Code:
    1. #include <QApplication>
    2.  
    3. #undef main
    4. int main(int argc, char *argv[])
    5. {
    6.  
    7. try
    8. {
    9. QApplication a(argc, argv);
    10. throw "ex";
    11. }
    12. catch(...)
    13. {
    14. // Do Nothing
    15. }
    16. return 0;
    17. }
    To copy to clipboard, switch view to plain text mode 
    bug.jpg
    Best regards.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: I don't catch exception in Qt

    what happens if you output something to the console in your catch section? (and don't forget to add a return value as well since main needs it)

    At the moment its hard to say if you re not catching anything since your catch section is not doing anything.
    The fact your screenshot shows that the application existed with an error suggests to me the exception is thrown, but since you didn't do anything with it, it is propagated all the way up, and since nothing else deals with it, your app simply exits with an error.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Not Able to put breakpoint inside catch() of try,catch block
    By vinothrajendran in forum Qt Programming
    Replies: 0
    Last Post: 15th July 2015, 09:22
  2. Replies: 5
    Last Post: 14th July 2014, 09:39
  3. how catch the key alt+f4 in my QApplication
    By waiter in forum Qt Programming
    Replies: 1
    Last Post: 10th August 2012, 07:25
  4. Replies: 3
    Last Post: 24th April 2012, 01:06
  5. Catch a Key, like designer
    By aekilic in forum Newbie
    Replies: 27
    Last Post: 7th May 2009, 11:01

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.