Something about assert () -- assertions in C #

Source: Internet
Author: User

How to discover bugs as early as possible to improve software qualityArticle. When we see the asserted technology, we feel that the asserted is everyProgramEssential basic skills. The bug in the program can be asserted to be found in the place closest to the place where it occurred to prevent the spread of the bug.
The use of assertions in. NET is using system. Dig. debug. Assertions generally take effect when the program is in debug mode. When the program is released (that is, the release mode), the compiler uses Conditional compilation to remove the assertions from the release DLL.
Use assertions in several scenarios, such:
1. Validity of method parameters
2. Assert the illegal situation and make continuous statements about the error situation and must handle it
3. assert any assumptions
4. Check the assumptions of the Program Development Environment (OS/Compiler/hardware) with assertions.
5. Write an error prevention program, and then use an asserted statement to declare an error after processing the error (usually the default statement in the switch statement is asserted)
6. Use assertions to ensure that unspecified features or functions are not used (if some of the previously defined functions have not yet been implemented, assertions should be made ).
I agree with the use cases of these assertions. However, I have the following questions:
1. For the first entry, since the assertions will be automatically removed from the program's release version by the compiler, we often develop a basic library, how can the public and protected modifier ensure the legitimacy of the parameters entered by the caller? (of course, if the caller is using a debug program, there is no problem ).
2. We release the program to users. Even if we use assertions during the development process, the quality of the program can be greatly improved, but there are still bugs in the program. So how can we find a bug in a release-version program that is the closest to the place where the bug is located, just like in the debugging phase? Currently, I only think that I can capture all exceptions at the top of the program and save the exception information and stack information as logs. However, at this time, it is difficult for us to locate this bug because it is hard to locate its place of birth.

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.