Results 1 to 4 of 4

Thread: Exception type loss

  1. #1
    Join Date
    Oct 2007
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Exception type loss

    Hi folks, I'm using some code which catches exceptions thrown from signals, like shown here: http://blog.ale-re.net/2007/04/exception-handling.html.

    Now, I'm having some problems: I have a chain of catch blocks for different exception types, but the exception returned is always caught as a generic std::exception, even though it is most definitely of more specific type. Here's some of the code:

    Qt Code:
    1. try {
    2. return QApplication::notify(receiver, event);
    3. }
    4. catch (Xmms::connection_error &ex) {
    5. qDebug("Caught connection_error: %s",ex.what());
    6. return false;
    7. }
    8. catch (Xmms::result_error &ex) {
    9. qDebug("Caught result_error: %s",ex.what());
    10. return false;
    11. }
    12. catch (std::exception &ex) {
    13. qDebug("Caught generic exception: %s",ex.what());
    14. }
    15. catch (...) {
    16. qDebug("Unknown exception!");
    17. abort();
    18. }
    To copy to clipboard, switch view to plain text mode 

    The type of exception thrown IS the more specific type, but is, for some reason, caught in the less specific handler.

    Is this a problem with Qt, or am I just mangling C++?

    Thanks very much for your help.

  2. #2
    Join Date
    Apr 2006
    Posts
    1
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Exception type loss

    Hi

    It would help to see more source. My only guess from what I see is that you forward declared the classes Xmms::connection_error and Xmms::result_error in the header file and did not include the respective headers in the source file.

    Sorry if you already have the answer and this is wrong.

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Exception type loss

    Quote Originally Posted by geordiejones View Post
    Hi

    It would help to see more source. My only guess from what I see is that you forward declared the classes Xmms::connection_error and Xmms::result_error in the header file and did not include the respective headers in the source file.

    Sorry if you already have the answer and this is wrong.
    No, that can't be it. It would have caused a compile error.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Exception type loss

    Perhaps Qt was built without exception support which would lead to qmake passing -fno-exceptions?
    J-P Nurmi

Similar Threads

  1. Installation on Fedora Core 4
    By jcr in forum Installation and Deployment
    Replies: 3
    Last Post: 29th January 2009, 01:34
  2. Replies: 6
    Last Post: 21st September 2007, 13:51
  3. dummy question(Error)
    By Masih in forum Qt Programming
    Replies: 12
    Last Post: 19th July 2007, 23:38
  4. 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.