Java Learning Anomaly < good programmer training camp >

Source: Internet
Author: User

<a href= "http://www.goodprogrammer.org/" target= "blank" >android training </a>------My Java notes and look forward to communicating with you!

1. Exception: The program is running in the event of an abnormal situation.

Exception Origin: The problem is also a specific thing in real life, can also be described in the form of Java classes. and encapsulated into objects. In fact, Java is a description of the abnormal situation after the object.

The problem is divided into two kinds: one is a serious problem, a non-serious one.

A) for serious, Java is described by the error class. For error, it is generally not written in a targeted code to handle it.

b) For non-critical, Java is described by the exception class. For exception, you can use a targeted processing method for processing.

Both error and exception have some common content. For example: abnormal information, causes of the cause and so on.

Throwable

|--error

|--exception

2. Exception handling: Java provides unique statements for processing.

try {

Code that needs to be detected;

}

catch (Exception class variable) {

Code to handle exception (processing mode)

}

finally {

Statements that are bound to be executed;

}

3. Handling of multiple exceptions:

1), when declaring an exception, it is recommended to declare a more specific exception. This can be handled more concretely.

2) The other side declares several exceptions, corresponding to a few catch blocks.  Do not define an extra catch block. If an inheritance relationship occurs in multiple catch blocks, the parent exception catch block is placed at the bottom.

4. When you set up catch processing, you must define a specific processing method in the catch. Don't simply define a e.printstacktrace (), or simply write an output statement.

The difference between 5.throws and throw:

1) throws is used on the function. Throw is used within a function.

2) The exception class followed by the throws. Can be followed by multiple. separated by commas. The throw is followed by an exception object.

Java Learning Anomaly < good programmer training camp >

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.