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

QApplication refuses exception handling on macOS arm64

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 6.2.0
    • Core: Event loop
    • None
    • arm64
    • macOS

    Description

      My program realizes exception handling in application events by catching exceptions in a derived notify(QObject*, QEvent*) method.

      It works well on Windows, Linux and macOS x86_64. However, on macOS arm64 try-catch does no longer catch any exception. Instead, the program crashes. I created a test scenario to prove it:

       

      struct Receiver : public QObject{
          bool event(QEvent* e) {
              if(e->type()==QEvent::User+1)
                  QException().raise();
              return QObject::event(e);
          }
      };
      
      int main(int argc, char *argv[]) {
          QApplication a(argc, argv);
          QEvent e(QEvent::Type(QEvent::User+1));
          Receiver obj;
          try{
              obj.event(&e);
          }catch(const QException& exn){
              qWarning("(1) catching %s", exn.what());
          }catch(...){
              qWarning("(1) catching unknown exception");
          }
          try{
              QCoreApplication::sendEvent(&obj, &e);
          }catch(const QException& exn){
              qWarning("(2) catching %s", exn.what());
          }catch(...){
              qWarning("(2) catching unknown exception");
          }
          return 0;
      }
      
      

      On any platform, this example will print as expected:

      (1) catching std::exception
      (2) catching std::exception
      

      However, on macOS running on arm64 this example will crash:

      (1) catching std::exception
      libc++abi.dylib: terminating with uncaught exception of type QException: std::exception
      

      Interestingly, the example will even succeed on macOS/arm64 when using QGuiApplication or QCoreApplication instead of QApplication.

      The exception seems to be not propagated to try-catch but instead causing a termination.

      The main difference between the working QGui/CoreApplication event handler and the crashing QApplication event handler is QApplicationPrivate::notify_helper where the problem seems to lie.

      I also tried to use NSException as well as objective C try-catch without success.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            docjambi Peter Droste
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes