Wednesday, 15 January 2014

c++ - Why cannot throw exceptions from destructors but can from copy constructor? -



c++ - Why cannot throw exceptions from destructors but can from copy constructor? -

this question has reply here:

throwing exceptions out of destructor 14 answers

it seems cannot throw exceptions destructors in case more 1 exception thrown destructor.

in effective c++ scott meyers uses vector illustration first element throws exception during destruction , later sec element throws- causing problems c++ (which cannot handle more 1 exception).

surely scenario (vectors manipulating elements , elements throwing exceptions) happen during re-create constructors implementing deep copying though?

edit:

are saying recursive-nature of dtors calling underlying dtors different re-create constructor?

exceptions shouldn't thrown destructors because when throw exception, compiler clean variables in scope, calling their destructors. you'd in bad shape if threw exceptions too.

c++ destructor copy-constructor

No comments:

Post a Comment