Warning C6320

Exception-filter expression is the constant EXCEPTION_EXECUTE_HANDLER. This may mask exceptions that were not intended to be handled

Remarks

This warning indicates the side effect of using EXCEPTION_EXECUTE_HANDLER constant in an __except block. In this case, the statement in the __except block will always execute to handle the exception, including exceptions you didn't want to handle in a particular function. It's recommended that you check the exception before handling it.

Code analysis name: EXCEPTIONEXECUTEHANDLER

Example

The following code generates this warning because the __except block will try to handle exceptions of all types:

#include <stdio.h>
#include <excpt.h>

void f(int *p)
{
   __try
   {
      puts("in try");
      *p = 13;  // might cause access violation exception
      // code ...
   }
   __except(EXCEPTION_EXECUTE_HANDLER) // warning
   {
      puts("in except");
      // code ...
   }
}

To correct this warning, use GetExceptionCode to check for a particular exception before handling it as shown in the following code:

#include <stdio.h>
#include <windows.h>
#include <excpt.h>

void f(int *p)
{
   __try
   {
      puts("in try");
      *p = 13;    // might cause access violation exception
      // code ...
   }
   __except(GetExceptionCode()==EXCEPTION_ACCESS_VIOLATION ?
               EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH)
   {
      puts("in except");
      // code ...
   }
}

See also

try-except Statement