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. Enabling exceptions to Qt project in Visual Studio 2017
Forum Updated to NodeBB v4.3 + New Features

Enabling exceptions to Qt project in Visual Studio 2017

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 963 Views 1 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.
  • T Offline
    T Offline
    TheEnigmist
    wrote on 16 Jan 2019, 18:47 last edited by
    #1

    I'm using Qt with Visual Studio, I'm able to code, compile and run it without any problem.
    Now I want to catch some error

    try{
       //known fail code
    }catch(...){
       qCritical() << "error!";
    

    But the application will crash instead of printing "error" in console! I read online that I need to add -exceptions flag and I tried adding this flag in:

    • C\C++ -> Command Line -> Additional Options
    • Qt Compilers (Meta-object and resource)

    But none of them enabled the exception handling!
    What am I wrong?

    J 1 Reply Last reply 17 Jan 2019, 05:35
    0
    • T TheEnigmist
      16 Jan 2019, 18:47

      I'm using Qt with Visual Studio, I'm able to code, compile and run it without any problem.
      Now I want to catch some error

      try{
         //known fail code
      }catch(...){
         qCritical() << "error!";
      

      But the application will crash instead of printing "error" in console! I read online that I need to add -exceptions flag and I tried adding this flag in:

      • C\C++ -> Command Line -> Additional Options
      • Qt Compilers (Meta-object and resource)

      But none of them enabled the exception handling!
      What am I wrong?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 17 Jan 2019, 05:35 last edited by
      #2

      @TheEnigmist Does your app really crash because of a C++ exception? What error is printed when it crashes?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      T 1 Reply Last reply 17 Jan 2019, 17:17
      1
      • J jsulm
        17 Jan 2019, 05:35

        @TheEnigmist Does your app really crash because of a C++ exception? What error is printed when it crashes?

        T Offline
        T Offline
        TheEnigmist
        wrote on 17 Jan 2019, 17:17 last edited by
        #3

        @jsulm Yes, I found out that I can't catch the error "index out of bound". While the code works if I put a simple throw std::runtime_error("error");
        My fault!

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 17 Jan 2019, 18:48 last edited by
          #4

          @TheEnigmist said in Enabling exceptions to Qt project in Visual Studio 2017:

          "index out of bound".

          Who should throw an exception here? At least no Qt containers...

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          T 1 Reply Last reply 18 Jan 2019, 09:46
          4
          • C Christian Ehrlicher
            17 Jan 2019, 18:48

            @TheEnigmist said in Enabling exceptions to Qt project in Visual Studio 2017:

            "index out of bound".

            Who should throw an exception here? At least no Qt containers...

            T Offline
            T Offline
            TheEnigmist
            wrote on 18 Jan 2019, 09:46 last edited by
            #5

            @Christian-Ehrlicher Yes, I found out that Qt container suppose an index is alredy checked before accessing a list. So I need to check it before and if the index goes over the size of the list raise an exception.

            V 1 Reply Last reply 18 Jan 2019, 09:54
            0
            • T TheEnigmist
              18 Jan 2019, 09:46

              @Christian-Ehrlicher Yes, I found out that Qt container suppose an index is alredy checked before accessing a list. So I need to check it before and if the index goes over the size of the list raise an exception.

              V Offline
              V Offline
              VRonin
              wrote on 18 Jan 2019, 09:54 last edited by VRonin
              #6

              @TheEnigmist said in Enabling exceptions to Qt project in Visual Studio 2017:

              Yes, I found out that Qt container suppose an index is alredy checked before accessing a list

              Not really: http://doc.qt.io/qt-5/qlist.html#value-1

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              2

              3/6

              17 Jan 2019, 17:17

              • Login

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