C6320

 

For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.

For the latest documentation on Visual Studio 2017, see C6320 on docs.microsoft.com. warning C6320: exception-filter expression is the constant EXCEPTION_EXECUTE_HANDLER. This may mask exceptions that were not intended to be handled

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

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 ...  
   }   
}  

try-except Statement

Show: