Search code examples
c++exceptionvisual-c++runtime-errorassert

Is there any way to avoid "Debug Assertion Failed" Window in C++?


This is the window that I want to prevent from showing when executing:

enter image description here

I know it is a bad practice but I am currently working on a code that collects all these exceptions and displays them in a different way, it would simply need the "Ignore" option to be executed automatically since the code is programmed so that right after I finished collecting the exception and can be processed


Solution

  • You should be able to

    #define NDEBUG
    

    which ought to suppress this. Secondarily, try undefining

    _DEBUG
    

    as parts of the Windows API use that.


    That said, I wouldn't do this: assertions are really there as a last resort and therefore are meant to help the programmer. If you want to handle an assertion in a different way then handle the situation that leads to it "by hand" before the assertion happens.

    Reference: https://en.cppreference.com/w/cpp/error/assert