Results 1 to 3 of 3

Thread: exception mechanism

  1. #1
    Join Date
    Jul 2009
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default exception mechanism

    i write like this,
    try
    {
    int i = 5;
    int j = i / 0;
    }
    catch (...)
    {
    qDebug("divided by zero.");
    }
    use qt in win32, but the catch can't catch the error, direct popup the microsoft's "sorry for inconvenice..." error box.
    anyone can teach me a method to solve this.
    can qt do it like mfc?

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: exception mechanism

    The C++ standard does not guarantee that an exception is thrown on a division by 0. You may need to read up on your compiler's options, maybe it is possible to configure it such that an exception is thrown in that case.
    But "usually" your app will just crash.

    See http://www.jdl.co.uk/briefings/divByZeroInCpp.html

    HTH

  3. #3
    Join Date
    Jul 2009
    Posts
    11
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: exception mechanism

    Quote Originally Posted by caduel View Post
    The C++ standard does not guarantee that an exception is thrown on a division by 0. You may need to read up on your compiler's options, maybe it is possible to configure it such that an exception is thrown in that case.
    But "usually" your app will just crash.

    See http://www.jdl.co.uk/briefings/divByZeroInCpp.html

    HTH

    thank you for you reply, is there any way like in mfc, try, catch(...), can catch all the error.and give the tips, it makes dubug easy.

Similar Threads

  1. exception catching speed
    By stefan in forum General Programming
    Replies: 10
    Last Post: 12th November 2008, 19:58
  2. Exception type loss
    By azdruid in forum Qt Programming
    Replies: 3
    Last Post: 6th November 2007, 20:06
  3. Exception handling in Qt 4.2.2
    By vishal.chauhan in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2007, 09:47
  4. c++, placement delete upon exception
    By stinos in forum General Programming
    Replies: 6
    Last Post: 31st October 2006, 15:38
  5. Exceptions and qApp->processEvents()
    By mcostalba in forum Qt Programming
    Replies: 3
    Last Post: 8th January 2006, 17:06

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.