Can I throw a C++ exception from a structured exception?
4 days ago
- #Compiler Optimization
- #C++
- #Exception Handling
- Customer wants to avoid using /EHa compiler switch due to performance and code size penalties.
- Proposes converting structured exceptions to C++ exceptions via an unhandled exception filter.
- Initial example works because printf might throw, keeping the try-catch block active.
- Without printf, the compiler optimizes out the try-catch block, causing the exception to be missed.
- Using /EHa ensures variables are stable for exceptions, preventing undefined behavior.
- Manual conversion without /EHa leads to potential undefined behavior due to uninitialized variables.
- Conclusion: Throwing C++ exceptions from structured exceptions requires /EHa to avoid undefined behavior.