Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

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.

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

Community Additions

ADD
Show:
© 2015 Microsoft