What is the point of `void func() throw(type)`?

前端 未结 6 1463
星月不相逢
星月不相逢 2020-12-18 11:59

I know this is a valid c++ program. What is the point of the throw in the function declarement? AFAIK it does nothing and isnt used for anything.

#include &l         


        
6条回答
  •  北荒
    北荒 (楼主)
    2020-12-18 12:53

    This is a C++ exception specification. It declares that the particular function will potentially throw a std::exception type.

    In general though exception specifications in C++ are considered a feature to avoid. It's an odd feature in that it's behavior is declared at compile time but only checked at runtime (very different from say Java's version).

    Here is a good article which breaks down the feature

    • http://www.gotw.ca/publications/mill22.htm

提交回复
热议问题