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. C++ Exception Handling
Forum Updated to NodeBB v4.3 + New Features

C++ Exception Handling

Scheduled Pinned Locked Moved General and Desktop
10 Posts 7 Posters 9.3k 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.
  • G Offline
    G Offline
    george
    wrote on 26 Feb 2013, 20:25 last edited by
    #1

    Hi
    I've installed in my Desktop PC (Windows 7 Pro) the last Qt Creator 2.6.2 having already installed the MS Visual C++ 2010 Express
    I face an issue with C++ Exception handling. Specifically, when I throw an exception my application crashes. Here is the output of the Qt creator:
    [quote]The program has unexpectedly finished.
    C:\Users\George\Documents\Tirage\Tirage-build-Desktop_Qt_5_0_1_MSVC2010_32bit-Debug\debug\Tirage.exe exited with code -1073741819

    Starting C:\Users\George\Documents\Tirage\Tirage-build-Desktop_Qt_5_0_1_MSVC2010_32bit-Debug\debug\Tirage.exe...
    The program has unexpectedly finished.
    C:\Users\George\Documents\Tirage\Tirage-build-Desktop_Qt_5_0_1_MSVC2010_32bit-Debug\debug\Tirage.exe exited with code -1073741819[/quote]

    Any help will greatly appreciated because I am totally new to the Qt development environment.
    Thanks in advance.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tzander
      wrote on 26 Feb 2013, 20:44 last edited by
      #2

      Qt itself doesn't use exceptions, but it supports it. In my experience you really should stay away from exceptions in C++ programming, whatever the libraries you use.

      I'm not sure why your app would crash, other than the obvious that the exception was not caught by you. ;) Qt doesn't have a problem with them, specifically.

      But, have you considered to not throw exceptions? As I said, a huge library Qt manages just fine without them. Likely its possible to avoid them in your app too ;)

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alizadeh91
        wrote on 26 Feb 2013, 22:22 last edited by
        #3

        As you are new i have to say that these exceptions are worst things in c++ and as Zander said you have to stay away from them . just step into your code to see where it happens. You can use qDebug() to see where it happens if your debugger is not set

        1 Reply Last reply
        0
        • T Offline
          T Offline
          TioRoy
          wrote on 27 Feb 2013, 03:30 last edited by
          #4

          -1073741819 = 0xC0000005

          In Windows means "Access violation".

          I agree with Thomas and Mostafa (avoid exceptions). Your code probably has an error not related to Qt.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Rondog
            wrote on 27 Feb 2013, 04:22 last edited by
            #5

            I think exceptions can be useful in some cases. I don't use them for everything but there are some situations they are quite suited for. Your code can be cleaner as it will focus on the task and not error handling.

            For example, if loading a file and a problem occurs the exception can describe the problem and, unlike a return value, cannot be ignored. You can use the information from the exception to pass onto the user such as missing file, truncated file, permissions, etc (instead of 'cannot load file').

            If your exceptions are caught in main() then this is an example of misuse.

            1 Reply Last reply
            0
            • U Offline
              U Offline
              utcenter
              wrote on 27 Feb 2013, 04:22 last edited by
              #6

              [quote author="Thomas Zander" date="1361911475"]Qt itself doesn't use exceptions, but it supports it. In my experience you really should stay away from exceptions in C++ programming, whatever the libraries you use.[/quote]

              I am pretty sure that Qt uses exceptions internally, however it doesn't throw exceptions at the user. You are still free to use exceptions where it is adequate to, most of the times it is possible to avoid using exceptions but there are a few cases where you cannot anticipate a scenario you cannot provision against and you do need to use exceptions.

              1 Reply Last reply
              0
              • T Offline
                T Offline
                tzander
                wrote on 27 Feb 2013, 06:42 last edited by
                #7

                bq. Rondog wrote:
                I think exceptions can be useful in some cases.

                The feature as is makes sense and is used in Java extensively, as well as other more modern languages. But if you care about code quality, then avoid them in C++ as they introduce too many bad effects to in the whole be a positive thing. With C++11 (at least on clang) one huge hole is kind-of plugged, it now just crashes your app when you throw an exception in a destructor. Whereas before it leaked memory. But think about it, crahing your app when throwing an exception there is deemed an improvement over the previous design. Consider how bad people think it was before :)

                bq. utcenter wrote:
                I am pretty sure that Qt uses exceptions internally, however it doesn’t throw exceptions at the user.

                It doesn't create them, specifically. Qt only catches system exceptions (like malloc throwing an bad_alloc) since it would be wrong to not to.

                1 Reply Last reply
                1
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 27 Feb 2013, 08:54 last edited by
                  #8

                  Hi,

                  If you don't use malloc'd memory, check that all your pointers are initialized (and don't forget to set them to NULL in the constructor if you don't allocate the objects right away)

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    george
                    wrote on 27 Feb 2013, 17:24 last edited by
                    #9

                    First of all I want to say thank you for all of your suggestions. I realised this forum is a very friendly forum.
                    I have to say that disagree and I believe that using exceptions handlers, a programmer can create a central piece of code and this is tied to object oriented logic.
                    I am try to learn the Qt environment and I can publish my code because it is a small project so far and you will have the oportunity to verify that there is no bug in it.
                    I am not convinced yet that Qt supports exceptions.

                    1 Reply Last reply
                    1
                    • T Offline
                      T Offline
                      tzander
                      wrote on 27 Feb 2013, 19:16 last edited by
                      #10

                      bq. I am not convinced yet that Qt supports exceptions.

                      Read the docs to see what Qt official position is :)
                      http://doc-snapshot.qt-project.org/4.8/exceptionsafety.html

                      1 Reply Last reply
                      1

                      1/10

                      26 Feb 2013, 20:25

                      • Login

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