Effective C + + (third Edition) Item29 for "Exception safe" is worth the effort

Source: Internet
Author: User

"Exception safe" has two conditions:

1, do not disclose any resources

You can manage resources by object (ITEM13).

2. Data corruption is not allowed

The exception security function provides one of the following three guarantees

A. Basic commitment

If an exception is thrown, everything inside the program remains in a valid state, but what state is unknown.

B. Strong guarantee

If the exception is thrown, the program state does not change.

C, non-throwing (nothrow) guarantee

Note: Do not change the state of an object in order to indicate that something happened, unless that thing really happened.

Copy and swap policies.

Summary: The exception security function does not leak resources or allow any data structure to be corrupted even if an exception occurs, such functions are divided into three possible guarantees, basic type, strong type, non-throwing anomaly.

"Strong guarantees" can often be implemented with copy and swap, but "strong guarantees" are not achievable or meaningful for all functions.

The "Exception security guarantee" provided by the function is usually the highest of the weakest in the exception security guarantee for each function that it invokes.

Effective C + + (third Edition) Item29 for "Exception safe" is worth the effort

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.