Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-139122

Can't set exception after QPromise was canceled

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 6.9.1
    • Core: Threads
    • None
    • All

      IMHO QFuture::waitForFinished should throw QPromise exception even if it was canceled.

      See the attached example for better understanding.

      Mind the Q_ASSERTs in the source code, all should pass.

       

      We should be able to set exceptions on all states but finished.

      It's very useful to catch a custom canceled exception in a try/catch

      block.

      e.g.

       

      class CanceledException : public QException
      {...}
      ...
      if (promise.isCanceled()
          promise.setException(CanceledException{});
      else
          promise.addResult(result);
      ...
       
      try {
          auto res = future.takeResult();
      } catch (const CanceledException &) {
          // handle canceled
      } catch (const AnotherSpeciticException &) {
          // AnotherSpecitic
      }
      

       

       

        1. main.cpp
          1 kB
          BogDan Vatra
        For Gerrit Dashboard: QTBUG-139122
        # Subject Branch Project Status CR V

            cnn Qt Core & Network
            taipan BogDan Vatra
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                There is 1 open Gerrit change