PDA

View Full Version : Exception type loss



azdruid
31st October 2007, 11:53
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:


try {
return QApplication::notify(receiver, event);
}
catch (Xmms::connection_error &ex) {
qDebug("Caught connection_error: %s",ex.what());
return false;
}
catch (Xmms::result_error &ex) {
qDebug("Caught result_error: %s",ex.what());
return false;
}
catch (std::exception &ex) {
qDebug("Caught generic exception: %s",ex.what());
}
catch (...) {
qDebug("Unknown exception!");
abort();
}

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.

geordiejones
6th November 2007, 19:38
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.

marcel
6th November 2007, 19:51
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.

jpn
6th November 2007, 20:06
Perhaps Qt was built without exception support which would lead to qmake passing -fno-exceptions?