Head first C # Chapter 10th Exception Handling page474

Source: Internet
Author: User

 

The worst catch in history
Block: Comment



If you want to catch
Block to keep the program running. If an exception is thrown, you capture it, and do not close the program or give an error message, but continue running. But sometimes, there is no such good thing.



Let's take a look at the Division operator below. It looks interesting. What's the matter?


 

You should handle exceptions instead of hiding them.


You can let the program continue to run does not mean that you have handled the exception. In the above Code, divide
() Method does not cause program crash. But what if other methods call this method and try to print the result? If the divisor is zero, this method may return an incorrect and unexpected value.



You should handle exceptions instead of adding comments and hiding them. If you cannot handle the exception, do not leave an empty or annotated catch.
Block! This makes it harder for others to find errors. It makes it easier for programs to throw exceptions because it is easy to find out the problem.



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.