-1

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?

user541686
  • 205,094
  • 128
  • 528
  • 886
  • No, it needs to be active at the call site. Provide evidence that those two cpu instructions *really* slow down your code. Long ago eliminated. Right now the "omigod, it's sucks mud" is a fishing expedition without merit. – Hans Passant Aug 14 '12 at 00:05
  • @HansPassant: Microsoft *itself* says (even in the VS 2012 docs) that *"`/EHa` may result in a less performant image because the compiler will not optimize a `try` block as aggressively, even if the compiler does not see a `throw`"*, and I don't think they're making a mistake when they say that (feel free to correct me). As for the code bloat (which is *not* mentioned), it's real: my executables get around ~10-20% bigger with `/EHa`. I never said it "sucks" (heck, at least `/EHa` is available), I just find it unnecessary to bloat my executables for something I don't use. – user541686 Aug 14 '12 at 00:14

1 Answers1

1

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");
   }
}
ctacke
  • 66,480
  • 18
  • 94
  • 155
  • I *could* make a wrapper function, but it feels kind of weird to throw, catch, and then throw again, just so I can get an `EXCEPTION_POINTERS` structure to feed into `CStructured_Exception`. Still, it's a valid alternative I guess... +1 – user541686 Aug 14 '12 at 00:17