201621123086 Java programming 10th Week of study summary

Source: Internet
Author: User

1. Summary of this week's study

    • Because the finally clause is always executed, it is possible to return from multiple points in a single method, and to ensure that important cleanup work is still performed.
    • When the constructor is invoked, cleanup of objects is generally used finally . However, it is important to note that if the constructor fails and throws an exception, finally it cannot be cleaned. To add one more layer of try-catch for shutdown processing. Similarly, for those constructors that can fail InputFlie , let's add a layer of try-catch accordingly.
2. Written assignment 1. Common exceptions 1.1 What anomalies do you often have in your previously written code, and what do you need to capture (why)? What should be avoided?

Frequently appearing are:

    • NullPointerException--NULL pointer exception
    • ClassCastException--Type conversion exception
    • IndexOutOfBoundsException--Array out of bounds exception

There is no need to capture, because these exceptions belong to unchecked exceptions.
To avoid these anomalies, we need to deal with special situations where exceptions occur. It is typical to use an if statement for type and array judgments.

1.2 What kind of exception requires the user to be sure to use capture processing?

Checked ExceptionRequires that the user be sure to capture the processing. Use the Try-catch or throws keyword to declare an exception that might be thrown

2. Handle exceptions to make your program more robust 2.1 experimental summary. And answer: How can you make your program more robust?
    • Experimental summary: In this problem, we can avoid empty elements in the array by putting i++ in the last sentence of the try clause, thus bypassing the error element and filling up the array.
    • A: Reasonable application of exception handling mechanism to make the program more robust. For example, in this problem, we can catch an element that does not conform to the required type as an exception through the exception handling mechanism.
3. Throw and throws3.1 Integer.parsetIntWhat is the benefit of having a large number of code throwing exceptions at the outset?

201621123086 Java programming 10th Week of study summary

Related Article

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.