有时我们无法确定一段代码会抛出何种异常,但是又希望能捕获这些异常
在不能确定异常类型时,首先应该尝试捕获std::exception, 通过what()方法可以得到一个较为详细的报错信息。
但有时,也可能会遇到一些不按套路出牌的代码,这时就需要使用catch(...)
来进行捕获,通过__cxa_exception_type
可以大致确定报错的类型,之后再修改代码进行进一步的处理
1 |
|
有时我们无法确定一段代码会抛出何种异常,但是又希望能捕获这些异常
在不能确定异常类型时,首先应该尝试捕获std::exception, 通过what()方法可以得到一个较为详细的报错信息。
但有时,也可能会遇到一些不按套路出牌的代码,这时就需要使用catch(...)
来进行捕获,通过__cxa_exception_type
可以大致确定报错的类型,之后再修改代码进行进一步的处理
1 | #include <exception> |