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 950 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 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?

    jsulmJ 1 Reply Last reply
    0
    • T TheEnigmist

      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?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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
      1
      • jsulmJ jsulm

        @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 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
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 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
          4
          • Christian EhrlicherC Christian Ehrlicher

            @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 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.

            VRoninV 1 Reply Last reply
            0
            • T TheEnigmist

              @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.

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on 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

              • Login

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