Item 38. Exception Safety Axioms

xiaoxiao2021-03-05  23

Item 38. Exception Safety Axioms

The axiom, recognized, no proven. It is necessary to prove that a geometric theorem is a series of axioms. To determine if the code is unusual, there is also a series of axioms to borrow.

-------------------------------------------------- ---- 1, exception is synchronized Exceptions Are Synchronous anomaly is synchronized, only when the function is called. The predefined type of algorithm, assignment, and other underlying operations do not cause an exception. (They may cause signals or interruptions, but that is not abnormal)

Operation is overloaded and template makes it complicated to determine whether an operation is often difficult to determine if a function will trigger a function call and a potential exception. For example, for user-defined type String: const char * a, * b; string c, d; // ... a = b; // no function call, no exceptionc = D; // function call, maybe an exception

For templates, things become more uncertain: Template void AtemplateContext () {t e, f; t * g, * h; // ... E = f; // function call? EXCEPTION? G = H; // no function call, no exception // ...} So all functions in the template have assumed that it is a function call, including INFIX Operators, and implicit conversion.

2, the sector is a safe IT's Safe To Destroy usually, the destructive function, Operator delete and Operator delete [] do not throw an exception. So the following exception capture is not necessary: ​​x :: ~ x () {try {delete ptr1_; delete ptr2_;} catch (...) {}}

Just like this: x :: ~ x () {delete ptr1_; delete ptr2_;}

3. Exchange does not throw an abnormality Swap Doesn't throw

Don't worry that there is an exception when there is an exchange operation using STL's Sort, Reverse, Partition, etc.

转载请注明原文地址:https://www.9cbs.com/read-33163.html

New Post(0)