Exception in Destructor C++

前端 未结 2 1817
清歌不尽
清歌不尽 2021-02-05 01:24

I am well aware of the fact that one should not throw any exception in destructor.

But as a part of making my grip on this concept,I coded this example :-



        
2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-05 01:58

    In your example, A() construct a temporary variable for A then destructs it immediately. Thus throw 10; is never executed.

    The throw statement taking place is in the destructor for A. When executing A::~A(), the program is not unwinding (i.e. cleaning up state from an exception) at that point. See "Destructors that throw" for example.

提交回复
热议问题