Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. SetUnhandledExceptionFilter not working in QEventLoop
Forum Update on Monday, May 27th 2025

SetUnhandledExceptionFilter not working in QEventLoop

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 6.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    ludek.vodicka
    wrote on 2 Sept 2012, 16:13 last edited by
    #1

    Hello there,

    I have a problem with SetUnhandledExceptionFilter in my Windows APP.

    I'm successfully using BreakPad in my console app for all platforms and everything works ok.Today I found out that crash handler doesn't work in Windows GUI app. After some testing I found out that problem isn't in BreakPad, but directly in SetUnhandledExceptionFilter.

    So I wrote following test code:

    @extern long __stdcall filter(EXCEPTION_POINTERS *p)
    {
    qDebug() << "App CRASH";
    return 0;
    }

    int buggyFunc()
    {
    delete reinterpret_cast<QString*>(0xFEE1DEAD);
    return 0;
    }

    int main(int argc, char * argv[])
    {
    QApplication app(argc, argv);
    qDebug() << "App start";

    SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER) filter);
    qDebug() << "CrashHandlerSet";

    //When I crash app here, crash handler is correctly executed
    //buggyFunc();

    Dialog dlg;
    dlg.exec(); //but when I call the same buggyFunc anywhere in the Dialog, application crash without executing filter

    //When I crash app here, crash handler is correctly executed too
    //buggyFunc();
    return 0;
    }@

    Crash handler stop working while QEventLoop is executed. As soon as event loop is exited, everything works correctly. I also test if ExceptionFilter is correctly set inside the Dialog event loop. The filter is correctly set also inside the Dialog.

    @void Dialog::on_pushButton_clicked()
    {
    LPTOP_LEVEL_EXCEPTION_FILTER filter = SetUnhandledExceptionFilter(NULL);
    //filter = 0x000000013f6496ab filter(struct _EXCEPTION_POINTERS * ptr64)
    delete reinterpret_cast<QString*>(0xFEE1DEAD);
    }@

    I tried Debug and also Release version of App but none of them work (I tried it with attached and detached debugger and of course executed separately from Visual studio).

    I will be appreciated for any help.
    Ludek

    1 Reply Last reply
    0
    • L Offline
      L Offline
      ludek.vodicka
      wrote on 2 Sept 2012, 16:41 last edited by
      #2

      After next searching I found that this problem occurs only on 64-bit windows. On 32-bit everything works ok too.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dikors
        wrote on 24 Feb 2013, 15:25 last edited by
        #3

        I had the same problem as ludek, because I'm using a 64-bit Windows. but as it mentioned in this blog(http://randomascii.wordpress.com/2012/07/05/when-even-crashing-doesnt-work/) it is sufficient to execute this function to enable crashing:
        @void enableCrashingOnCrashes()
        {
        typedef BOOL (WINAPI *tGetPolicy)(LPDWORD lpFlags);
        typedef BOOL (WINAPI *tSetPolicy)(DWORD dwFlags);
        const DWORD EXCEPTION_SWALLOWING = 0x1;

        HMODULE kernel32 = LoadLibraryA("kernel32.dll");
        tGetPolicy pGetPolicy = (tGetPolicy)GetProcAddress(kernel32,
                    "GetProcessUserModeExceptionPolicy");
        tSetPolicy pSetPolicy = (tSetPolicy)GetProcAddress(kernel32,
                    "SetProcessUserModeExceptionPolicy");
        if (pGetPolicy && pSetPolicy)
        {
            DWORD dwFlags;
            if (pGetPolicy(&dwFlags))
            {
                // Turn off the filter
                pSetPolicy(dwFlags & ~EXCEPTION_SWALLOWING);
            }
        }
        

        }@

        1 Reply Last reply
        0
        • J Offline
          J Offline
          JmsMldcs
          wrote on 14 Aug 2016, 23:04 last edited by JmsMldcs
          #4

          I'm having the same problem as Ludek. On 64-bit Windows 10, with a 64-bit executable.

          Calling crashing code before or after .exec or crashing on a secondary thread (tested with std::async and QThread) results in the UnhandledExceptionFilter being called. If called from an event processed in the exec function the UnhandledExceptionFilter is not called.

          GetProcessUserModeExceptionPolicy and SetProcessUserModeExceptionPolicy are no longer present in kernel32.dll, so cannot experiment with them.

          Has anyone had any luck with this? Any help is much appreciated :)
          James

          1 Reply Last reply
          0
          • J Offline
            J Offline
            JmsMldcs
            wrote on 17 Aug 2016, 21:56 last edited by
            #5

            Found a related bug here https://bugreports.qt.io/browse/QTBUG-50061.

            The issue is related to the QML JIT. As suggested setting QV4_FORCE_INTERPRETER=1 does remove the issue. We are performance heavy application so we are unable to use it.

            1 Reply Last reply
            0
            • P Offline
              P Offline
              Pulsford23
              Banned
              wrote on 24 Sept 2018, 07:27 last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              -1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved