h**k 发帖数: 3368 | 1 What happens if an exception is throws from an object's destructor?
What happens if an exception is throws from an object's constructor? | z****e 发帖数: 2024 | 2 1. very bad idea. not necessarily to have crash, but very well possible.
reason: when an regular exception is thrown, the destructors for existing
objects are called. if within these destructors, an other exception is
thrown, then the program will terminate immediately. very bad. none of the
exceptions are caught.
2. fine. some additional attention is needed, such like avoid naked pointers
in ctor, etc. | h**k 发帖数: 3368 | 3
I agree. Someone said NEVER EVER throw an exception from destructors.
pointers
【在 z****e 的大作中提到】 : 1. very bad idea. not necessarily to have crash, but very well possible. : reason: when an regular exception is thrown, the destructors for existing : objects are called. if within these destructors, an other exception is : thrown, then the program will terminate immediately. very bad. none of the : exceptions are caught. : 2. fine. some additional attention is needed, such like avoid naked pointers : in ctor, etc.
|
|