Hello,

I need to throw an exception across a thread boundary.
I thought this was possible with QtConcurrent::Exception after reading the docs (http://doc.trolltech.com/4.4/qtconcu...exception.html) however this does not seem to work for me. I tested the following code with gcc 4.3 and with VS2008:

Qt Code:
  1. #include <QtCore>
  2.  
  3. class MyException : public QtConcurrent::Exception
  4. {
  5. public:
  6. void raise() const { throw *this; }
  7. Exception *clone() const { return new MyException(*this); }
  8. };
  9.  
  10. void runInOtherThread()
  11. {
  12. qDebug("other thread");
  13. throw MyException();
  14. }
  15.  
  16. int main(int argc, char* argv[])
  17. {
  18. QCoreApplication a(argc, argv);
  19. try
  20. {
  21. QtConcurrent::run(&runInOtherThread);
  22. }
  23. catch(MyException &e)
  24. {
  25. qDebug("exception caught");
  26. }
  27. return a.exec();
  28. }
To copy to clipboard, switch view to plain text mode 

I would expect to end up in the catch block in the main() function. However i get the following output:
Qt Code:
  1. $ ./exceptiontest
  2. other thread
  3. Qt Concurrent has caught an exception thrown from a worker thread.
  4. This is not supported, exceptions thrown in worker threads must be
  5. caught before control returns to Qt Concurrent.
  6. terminate called after throwing an instance of 'MyException'
  7. what(): std::exception
  8. Aborted
  9. $
To copy to clipboard, switch view to plain text mode 

The warning is printed in QThreadPoolThread::run().
This conflicts with my interpretation of the manual, which says:
Qt Code:
  1. Qt Concurrent supports throwing and catching exceptions across thread boundaries, provided that the exception inherit from QtConcurrent::Exception and implement two helper functions:
To copy to clipboard, switch view to plain text mode 

But probably i'm just doing something wrong here
Any help or pointers would be very much appreciated

thanks,
glenn