Results 1 to 15 of 15

Thread: use try cacth exception

  1. #1
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    16
    Qt products
    Qt3 Qt4
    Platforms
    Windows Symbian S60

    Default use try cacth exception

    Can i use "try catch" in app?
    I try to write a simple example ,in app I use "try catch" but unsuccess?
    Can i help you?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: use try cacth exception

    Show us what you tried so far.

  3. #3
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    16
    Qt products
    Qt3 Qt4
    Platforms
    Windows Symbian S60

    Default Re: use try cacth exception

    i tried
    Qt Code:
    1. int t =1;
    2. int t1 = 0;
    3. try
    4. {
    5. float t2 = t/t1;
    6. }
    7. catch (...)
    8. {
    9. qDebug()<<"test";
    10. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: use try cacth exception

    and what happens?

  5. #5
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    16
    Qt products
    Qt3 Qt4
    Platforms
    Windows Symbian S60

    Default Re: use try cacth exception

    app is wrong. why try catch do not active?

  6. #6
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: use try cacth exception

    what means "app is wrong"?

  7. #7
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    16
    Qt products
    Qt3 Qt4
    Platforms
    Windows Symbian S60

    Default Re: use try cacth exception

    app is quit and it does not run command "Qdebug()<<"test"

  8. #8
    Join Date
    Jun 2011
    Location
    Chennai, India
    Posts
    30
    Thanks
    13
    Thanked 6 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: use try cacth exception

    What compiler are you using? I think in some cases, the compiler doesn't generate an exception

  9. #9
    Join Date
    Oct 2010
    Posts
    55
    Thanks
    1
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    9

    Default Re: use try cacth exception

    Division by zero doesn't throw an exception in Standard C++.

  10. #10
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    16
    Qt products
    Qt3 Qt4
    Platforms
    Windows Symbian S60

    Default Re: use try cacth exception

    if Qt does not catch exceptions, it will crashes...
    so, does Qt catch exceptions anywhere?

  11. #11
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: use try cacth exception

    what does Qt have to do with this? it's c++ that does not throw an exception in this case, as helloworld stated.

    you can use try...catch in your qt app. you can catch exceptions. but you can't catch exceptions that are never thrown...

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

    Default Re: use try cacth exception

    Quote Originally Posted by jindoniit View Post
    so, does Qt catch exceptions anywhere?
    Yes, it does. Not that this matters in any way...
    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.


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

    Default Re: use try cacth exception

    Floating point errors don't throw exceptions. They generate signals. Not Qt signals.

    If you need to respond to them, you need to install your own system signal handler. See the C++ signal() call for information on how to do this.

    If all you want to do is avoid division by zero, simply check that the divisor is not equal to zero before performing the operation, and either throw your own exception or put your own error handling in place.

  14. #14
    Join Date
    Jun 2011
    Posts
    35
    Thanks
    16
    Qt products
    Qt3 Qt4
    Platforms
    Windows Symbian S60

    Default Re: use try cacth exception

    Thanks all for reply
    I only want to do is avoid app crashes by catch unforeseen error

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

    Default Re: use try cacth exception

    Quote Originally Posted by jindoniit View Post
    Thanks all for reply
    I only want to do is avoid app crashes by catch unforeseen error
    Then fix the errors. Exceptions won't do that for you. They are mostly for handling forseen errors.
    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.


Similar Threads

  1. Unhandle Exception
    By samar in forum Qt Programming
    Replies: 2
    Last Post: 9th June 2011, 23:22
  2. Unhandled Exception from DLL QT 4.6.0
    By qlarity_three in forum Newbie
    Replies: 2
    Last Post: 5th February 2010, 19:11
  3. Qt and exception support....
    By sergey_85 in forum Qt Programming
    Replies: 1
    Last Post: 28th November 2009, 12:17
  4. exception mechanism
    By guchangyuan in forum Qt Programming
    Replies: 2
    Last Post: 10th August 2009, 04:57
  5. exception
    By AnithaRagupathy in forum Qt Programming
    Replies: 1
    Last Post: 14th November 2007, 09:59

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.