Use of Assert

Source: Internet
Author: User

It's not always clear when to use assert and when to use if. Now record it.

Assert is used to check the legality of a parameter and an expected result, etc., assert only in debug mode. Assert is programmer-oriented, not user-oriented, it is mainly convenient for programmers to check and quickly locate the program's logic errors (the programmer's own problems), if you encounter errors while debugging the program will immediately terminate the program and prompt the wrong location. It can be said that assert is only a tool provided to the programmer and cannot be counted as part of the program logic.

If else is part of the program logic that indicates what logic should be executed when a situation arises. For example, when a user enters a parameter that is not in scope, you can go to the logic that prompts the user for re-entry.

Use of Assert

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.