Can anyone explain C++ exception specifications to me?

前端 未结 5 1458
野趣味
野趣味 2021-02-07 21:24

Can anyone explain Exception Specifications as used in C++ ?

  • When are they used (I have rarely seen it used in code)
  • What are the pros and cons (benefits/
5条回答
  •  余生分开走
    2021-02-07 22:12

    When are they used (I have rarely seen it used in code)
    Hopefully never as they are deprecated in the next version of C++ due for standardization next year.

    What are the pros and cons (benefits/disadvantages) of using exception specifications?
    They provide a way for readers of your code to know exactly what exceptions a function is allowed to throw. The problem is, that if an unexpected exception (one not in the specification) is thrown, then the program will be terminated (by default).

提交回复
热议问题