A forgotten corner-exception (1)

Source: Internet
Author: User

Very attractive title. Today, we will not introduce you, but discuss some issues with you.

In the past few years of development, many projects, large and small, have gone through, but no matter in that project, there is no realExceptionComplete processing. Although we are learningC #We often see this type of introduction, but have we actually applied it?

Let's take a look at what isException

ExceptionThe explanation is abnormal.ProgramWhen debugging, you will encounter it more or less (If your program has never met, you are a genius ).RicherIn its book, it is repeatedly mentioned that,ExceptionIs a violation of the original interface. I couldn't understand it at first. When I really thought about this issue and went deep into this topic, I realized that it was a violation, common exceptions such as parameter errors and empty objects are caused by violations of the interface definition.

Example:

VaRSTR = "int ";

IntI =Convert. Toint32 (STR );

This conversion will throw an exception, althoughConvert. toint32 (string Str)Is a valid method, but the inputStrMust be convertibleIntOtherwise, an exception is thrown back. This is a violation of its method definition.

ExceptionNot equalError

errors are widely interpreted and may contain exceptions, but exception not equal to error

An exception is briefly introduced, I think many developers must be very familiar with it, but what we do is not good at actually processing it, many people think that the original system exception is enough for us to find bug now, we only need to test it in place, but this is a wrong idea, this is also a terrible idea, because you don't know when and where to throw an exception you don't know. win form it is terrible for applications to encounter exceptions. If they are not processed, the application will be closed directly. In Web application , although httpapplication encapsulates unprocessed exceptions and throws a unhandlingexception you need to know that your website faces different users, what will happen if they see such a result? Some people may say that I wrap it on an error page, which looks friendly. Yes. This is a solution. Have you ever thought about it? How do you know exception what? Your website staff will notify you as soon as they meet you, but what if they are customers?

We can't keep waiting. We are qualified programmers and ourCodeIt's our child. We have to give him the best, including his illness. We have to treat him right away. If we don't get sick, we have to take a vaccine and increase our resistance, we also need to think about the solution in time to avoid confusion at that time.Therefore, we must have a good solution mechanism to cope with various emergencies..

Is there a perfect solution? I can tell you for sure, no. No matter what applications you develop, your developers, environments, programming habits, and development processes will all affect this solution. My point is to start with people.

Code is dead, people are living, and we must always realize that we are born to create programs, not to solve the work, the beauty of programs, and the beauty of people, procedureBug, Is a personBugThe quality of a program actually shows a person's thinking. Exceptions in an application do not mean that the developer is incompetent. This may be a good opportunity for you to better learn the solution.

processing exception " " This is introduced in a book recently. This is the Chinese version found online and is very good. These specifications allow us to handle a lot of exception . However, the sentence begins with a human being, developers' applications and developers' thinking are very important. A company's unified technical specifications are very necessary. In other code, you can handle exceptions at will, you must follow this rule, because it is really important and easy to ignore, and every company should provide training for it, review , are indispensable.

Unit Test

Although unit testing is also a solution, not every unit test will solve the problems in your system.Bug.

I have said so much. In fact, I want to let everyone know the importance of exceptions and let everyone think about these issues as much as possible during the development process to avoid unexpected consequences.

In the future, I will bring you some solutions, and develop a set of commonExceptionhandlingOf course, this also requires your support for me:P

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.