在Visual Studio 中使用try except , compile的时候遇到如下error:
__try in functions containing objects with destructors
原因是在使用try/except 的时候,不可以在函数中有object unwinding and destruction.
解决办法, 参考微软: Compiler Error C2712
- Move code that requires SEH to another function
- Rewrite functions that use SEH to avoid the use of local variables and parameters that have destructors. Do not use SEH in constructors or destructors
- Compile without /EHsc
我在项目中的解决方法是采用的第三种:
打开项目的property, C/C++ –> Enable C++ Exceptions , 改为No.