Pay back the chicken debt: how to better and faster debug (good things stick to the top of the Day)

Source: Internet
Author: User

Some people say that web programmers are not really programmers. They were angry when they heard this sentence, but think about it carefully. This still makes sense. It can be said that most web programmers cannot be real programmers, because they focus most of their attention on implementing functions, and do not care about what programmers must master. You can say that you want to run without crawling.
You may not agree with the above, but ask yourself, apart from modifying the example implementation function, how much do you know about some basic things? Let's not talk about complicated things such as object-oriented. Let's talk about simple troubleshooting and Error Correction. How much have you done?
Think about it. I am afraid that Programmers spend most of their time debugging every day. But how many people really have a reasonable and scientific understanding of debugging? The previous web programming languages, such as asp, php, and cgi, have weak debugging functions. But now c # and java provide a wide range of debugging methods, but how much have you used? You may be familiar with every class, method, and attribute of System. Data. SqlClient. How much do you know about System. Diagnostics?
Modern programming languages such as c ++, java, and c # place great importance on error prevention and handling. Here I will talk about troubleshooting and Error Correction in c, I hope you can learn some useful things from them. I hope you will not hear the first sentence of the article in the future.
What is the ideal debug status? That's defect free, no bug. But some people have already said that if there is no bug, is it a program? Win2000 has more than 60000 bugs. So what we need to do is to prevent bugs as much as possible. After a bug occurs, we can quickly locate the problem and fix it .. Net provides a wide range of debugging methods. Besides some debug-related nampespace, the c # language also has relevant content. Frequently Used Conditional compilation, try/catch, trace, and Assert. If you are familiar with these techniques and use them in a comprehensive manner, debug will no longer be a nightmare, even if there is a problem like this, the forum will be full of people and ask, "I have made another mistake here. Why? ". Next I will talk about the use of these methods.
1. catch exceptions (try/catch/finally)
I don't need to say that everyone knows its role is to catch all exceptions that may cause errors in the program, and then add your own handling measures to keep the program running, if exceptions are not captured, the program will terminate and simply send the error message to the customer.
Therefore, you should capture exceptions when performing any operations that may cause errors, as shown in the following example.
/// <Summary>
/// Obtain the database connection

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.