winapivisual-c++sehstructured-exception

How to get the benefits of /EHa with /EHsc, on a particular function?


If I know that a particular extern "C" function in my program (say, RaiseException) is the only function that raises SEH exceptions, and I want them converted to C++ exceptions, is there any way for me to "selectively enable" /EHa for that function, so that the exceptions get converted to CStructured_Exception without bloating or slowing down the rest of the program as normally caused by /EHa?


Solution

  • There's obviously no compiler option to do that. Maybe:

    void RaiseException() {
       __try {
          // do something that might throw here...
       }
    
       __except(EXCEPTION_EXECUTE_HANDLER) {   
          throw std::exception("structured exception");
       }
    }