C++ catch(std::exception & e ) vs. catch(…)

后端 未结 4 1888
傲寒
傲寒 2020-12-11 03:58

I know the difference in handling of both of these catches, but what does it take for the ellipse to catch something the std::exception catch wouldn\'t catch?

For ex

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-11 04:22

    As written, the throw statement throws an object whose type is derived from std::exception, so it's caught by the first catch clause. If you change the throw to throw 3; the exception will be caught by the second catch clause, not the first.

提交回复
热议问题