Search code examples
visual-studiovisual-c++visual-studio-2022

How to prevent "Debug assertion failed window" appearing in Visual studio C++ 2022?


I'd like to prevent "Debug assertion failed window" appearing in Visual studio C++ 2022 on errors handled by the debugger, in a way like I pressed "Retry" in this window to get straight to the code.

Justification

  1. In 99% of cases I press this "Retry" button, so I don't see any value neither in "Abort" (I can stop the app myself) nor in "Ignore" (whatever it is assumed to do), so this is just an excessive step.
  2. It produces annoying sound which I can't turn off, since I need it in other cases.

Is this possible keeping debug assertions working and debugger handling these things? I just want to skip the window.


Solution

  • Thanks to John Omielan's comment above, the answer from here: Windows CRT and assert reporting (abort, retry, ignore) solved the problem:

    int __cdecl CrtDbgHook(int nReportType, char* szMsg, int* pnRet)
    {
        return TRUE;//Return true - Abort,Retry,Ignore dialog will *not* be displayed
        return FALSE;//Return false - Abort,Retry,Ignore dialog *will be displayed*
    }
    int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
    {
        _CrtSetReportHook2(_CRT_RPTHOOK_INSTALL, CrtDbgHook);
        assert(false);
        getch();
        return 1;
    }