Results 1 to 7 of 7

Thread: Any idea to get a more prowerful try - catch ?

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Any idea to get a more prowerful try - catch ?

    I have implemented a try catch with
    Qt Code:
    1. catch (exception & e)
    2. { Q_debug()<< "Standard exception: "<< e.what()";
    3. }
    To copy to clipboard, switch view to plain text mode 
    But my program crash and I have not reach the catch line...
    (Only I can detect some simple errors, but in example when save a stl::vector with less information that expected, my app simply chrash)
    Any idea ?
    Is there any more I can write to have more control on errors ?
    The errors I want to control are mainly related with c++ code, not on QT objects
    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Any idea to get a more prowerful try - catch ?

    If something doesn't throw exceptions then don't expect to catch one.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Any idea to get a more prowerful try - catch ?

    If you don't know what is going to be thrown how can you possibly catch it? The only real solution is the catch all "catch (...)", but of course you'll get no more information in this case and OS errors (such as memory access violations) are normally not caught unless you use OS specific exception catching.

  4. #4
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Any idea to get a more prowerful try - catch ?

    'app simply crash' doesn't provide any meaningful information, and there are many ways for an app to crash that don't involve throwing exceptions.

    Run your app in a debugger, or use stdout debugging to examine intermediate variable contents.

  5. #5
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Any idea to get a more prowerful try - catch ?

    Ok, but then all converst into a simple control of things using if's , isn't.
    So, I dont see the convenience of using exceptions control, because it seems that only can deal with some errors, isn't.
    What is your opinión about this ? I have seen that is normally to avoid exceptions catching.
    And I have not seen any of this into QT examples...
    Thanks

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Any idea to get a more prowerful try - catch ?

    Exceptions are not some magical general mechanism for handling errors. Specific code has to be implemented in a way that makes it throw exceptions in particular exceptional situations. Then some other code that uses this code can catch those exceptions and handle them. Qt doesn't throw exceptions itself so there are no examples of using exceptions with Qt.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Any idea to get a more prowerful try - catch ?

    tonnot, consider the difference:

    Qt Code:
    1. if (!somefunction()) {
    2. //clean up
    3. return;
    4. }
    5. if (!someOtherfunction()) {
    6. // clean up
    7. return;
    8. }
    9. // etc.
    To copy to clipboard, switch view to plain text mode 

    with the functions themselves also having cleanup code...

    and

    Qt Code:
    1. try {
    2. somefunction();
    3. someOtherfunction();
    4. } catch (someException &e) {
    5. // cleanup, knowing what went wrong.
    6. }
    To copy to clipboard, switch view to plain text mode 

    Much nicer.

Similar Threads

  1. A Hippie Idea
    By qtoptus in forum Qt Programming
    Replies: 9
    Last Post: 17th December 2010, 23:28
  2. ???any one have idea about this ???
    By damodharan in forum Qt Programming
    Replies: 1
    Last Post: 29th May 2010, 09:08
  3. skins idea
    By CopyrightPhilly in forum General Discussion
    Replies: 1
    Last Post: 11th November 2007, 15:16
  4. UI Idea please
    By munna in forum General Discussion
    Replies: 1
    Last Post: 9th May 2006, 11:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.