Udostępnij za pośrednictwem


C6320

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.

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

Reference

try-except Statement