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
Forum Update on Monday, May 27th 2025

About exception

Scheduled Pinned Locked Moved Unsolved General and Desktop
exceptiontry catchtrycatch
4 Posts 3 Posters 556 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 7 Jan 2022, 08:12 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 J 2 Replies Last reply 7 Jan 2022, 08:14
    0
    • Q qt_learning
      7 Jan 2022, 08:12

      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 Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 7 Jan 2022, 08:14 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
        7 Jan 2022, 08:12

        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 Offline
        J Offline
        JonB
        wrote on 7 Jan 2022, 09:01 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 1 Reply Last reply 7 Jan 2022, 09:23
        0
        • J JonB
          7 Jan 2022, 09:01

          @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 Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 7 Jan 2022, 09:23 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

          2/4

          7 Jan 2022, 08:14

          • Login

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