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. About exception
QtWS25 Last Chance

About exception

Scheduled Pinned Locked Moved Unsolved General and Desktop
exceptiontry catchtrycatch
4 Posts 3 Posters 553 Views
  • 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.
  • Q Offline
    Q Offline
    qt_learning
    wrote on last edited by
    #1

    Hi
    I am testing try / catch
    so I coded as below

    int a = 100, b = 0;
    try {
        int c = a/b;
    }  catch (...) {
        qDebug() << "error A";
    }
    

    When I am debuging that code, An excption occurred in "int c = a/b;"
    but it didnot go inside the catch statement.
    the excepton message is as follows

    4c1046bb-4ce4-4b01-bf3a-640fc99be978-image.png

    How do I make the program go into a catch statement when an exception occurs in a try statement?

    J.HilkJ JonBJ 2 Replies Last reply
    0
    • Q qt_learning

      Hi
      I am testing try / catch
      so I coded as below

      int a = 100, b = 0;
      try {
          int c = a/b;
      }  catch (...) {
          qDebug() << "error A";
      }
      

      When I am debuging that code, An excption occurred in "int c = a/b;"
      but it didnot go inside the catch statement.
      the excepton message is as follows

      4c1046bb-4ce4-4b01-bf3a-640fc99be978-image.png

      How do I make the program go into a catch statement when an exception occurs in a try statement?

      J.HilkJ Online
      J.HilkJ Online
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @qt_learning
      You need to check it yourself and throw an exception. Integer divide by zero is not an exception in standard C++, its still "undefined behaviour"


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      3
      • Q qt_learning

        Hi
        I am testing try / catch
        so I coded as below

        int a = 100, b = 0;
        try {
            int c = a/b;
        }  catch (...) {
            qDebug() << "error A";
        }
        

        When I am debuging that code, An excption occurred in "int c = a/b;"
        but it didnot go inside the catch statement.
        the excepton message is as follows

        4c1046bb-4ce4-4b01-bf3a-640fc99be978-image.png

        How do I make the program go into a catch statement when an exception occurs in a try statement?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @qt_learning
        https://stackoverflow.com/questions/6121623/catching-exception-divide-by-zero

        @J-Hilk
        I think https://stackoverflow.com/a/26315860/489865 is saying MSVC (only) has a /EHa option for extended exceptions?

        J.HilkJ 1 Reply Last reply
        0
        • JonBJ JonB

          @qt_learning
          https://stackoverflow.com/questions/6121623/catching-exception-divide-by-zero

          @J-Hilk
          I think https://stackoverflow.com/a/26315860/489865 is saying MSVC (only) has a /EHa option for extended exceptions?

          J.HilkJ Online
          J.HilkJ Online
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @JonB said in About exception:

          /EHa

          What /EHa does is chaniging the definition of an exception, extending it, wrapping system level errors as exceptions. This is non-standard and AFAIK MSVC specific.

          I would stay as far away from it as possible.


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          1 Reply Last reply
          3

          • Login

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