Search code examples
c++winapiexceptiondivide-by-zero

Why does SEM_NOGPFAULTERRORBOX suppress division by zero as well?


It seems that SetErrorMode(SEM_NOGPFAULTERRORBOX), suppresses division by zero.

Code to reproduce:

SetErrorMode(SetErrorMode(0) | SEM_NOGPFAULTERRORBOX); // Comment out this line and an error dialog will appear.
int a = 5;
printf("%d", 1/(a-5));

Why is that? From the name I assume it should suppress only General Protection Fault, which has nothing to do with division by zero.


Solution

  • From the MSDN reference page:

    The system does not display the Windows Error Reporting dialog.

    This means that when you set the flag, it suppresses all error dialogs.