[Qt5-feedback] new Qt5 - great! - but: What about exceptions?

Craig.Scott at csiro.au Craig.Scott at csiro.au
Sat May 14 01:33:42 CEST 2011


On 14/05/2011, at 6:56 AM, Thiago Macieira wrote:

> On Friday, 13 de May de 2011 15:38:21 Keith Gardner wrote:
>> If you don't add exceptions, could you at least add the ability to transport
>> exceptions across thread boundaries?
> 
> How do you suggest doing that? What happens if the exception is thrown by 
> reference and isn't copyable? What happens if an exception is thrown with a 
> type that doesn't derive from std::exception?

You also get into problems with exporting symbols when using std::exception. You cannot reliably catch std::exception across module boundaries, meaning an exception thrown in one shared library to be caught in another - many respected C++ people strongly recommend against doing this, and for good reason. On some systems, the catching module will actually have a different internal type for std::exception than the throwing module, so even though they *look* like the same type to the developer, internally they are not recognised as such and you end up scratching your head trying to work out why your exception is not being caught.

A related problem is that on Windows (Visual Studio compilers at least), std::exception is not a publicly exported symbol. This means you cannot export any classes you derive from it either. Thus, once again, you can't catch an exception of your std::exception subclass thrown in a different module to the one in which you want to catch it. so the problem isn't just restricted to the existing exception classes, it also applies to any class you derive from them.

The above makes the value of supporting exceptions in Qt somewhat muted. Yes, Qt could go ahead and define its own exception class hierarchy, but it would have to be completely separate from std::exception and the other exception classes defined for the C++ standard library.

It should also be pointed out that there's nothing stopping you from using exceptions in your own code, it's just that Qt itself doesn't generate them or try to catch them (with one notable exception (pun not intended), that being wrapped around the main event loop to catch all exceptions with (...) to emit a general warning message). We do this in our own code, which is how we discovered the problems described above. ;)

--
Dr Craig Scott
Computational Software Engineering Team Leader, CSIRO (CMIS)
Melbourne, Australia





More information about the Qt5-feedback mailing list