Http://blog.csdn.net/jixingzhong/article/details/1844531
The constructor exception can be summarized as follows:
1. In C ++, the only way to notify the object construction failure is to throw an exception in the constructor;
2. When a constructor throws an exception, the Destructor will not be executed;
3. When an exception is thrown, its sub-objects are parsed in reverse order. (Refer to the analysis process)
Destructor exceptions are relatively complex, and a conflict exists,ProgramWill Crash directly: When an exception is called "Stack unwinding" [note], an exception is thrown from the destructor, c ++ runs in an uncertain situation. Therefore, the C ++ language guarantees that, at this point, the system will call terminate () to kill the process. Therefore, when processing another exception, do not throw an exception from the destructor. Summary:
1. The execution of destructor in C ++ should not throw an exception;
2. when some exceptions (even a little possible) occur in a destructor, you must completely encapsulate these exceptions in the destructor, never let it throw out the function (this is a perfect trick! Haha !);
3. When an exception is thrown, its sub-objects are parsed in reverse order. (Refer to the analysis process)
References:
[1] exception and error handling (C ++ FAQ), http://www.sunistudio.com/cppfaq/exceptions.html
[2] constructor thrown exception, http://51cmm.csai.cn/ExpertEyes/No143.htm
[3] exceptions thrown in destructor, http://se.csai.cn/ExpertEyes/No144.htm