throwing exceptions out of a destructor

后端 未结 16 2287
暗喜
暗喜 2020-11-22 00:23

Most people say never throw an exception out of a destructor - doing so results in undefined behavior. Stroustrup makes the point that \"the vector destructor e

16条回答
  •  忘掉有多难
    2020-11-22 01:13

    From the ISO draft for C++ (ISO/IEC JTC 1/SC 22 N 4411)

    So destructors should generally catch exceptions and not let them propagate out of the destructor.

    3 The process of calling destructors for automatic objects constructed on the path from a try block to a throw- expression is called “stack unwinding.” [ Note: If a destructor called during stack unwinding exits with an exception, std::terminate is called (15.5.1). So destructors should generally catch exceptions and not let them propagate out of the destructor. — end note ]

提交回复
热议问题