Java learning notes -- exceptions, Java learning notes --

Source: Internet
Author: User

Java learning notes -- exceptions, Java learning notes --

The Throwable Java class is used to indicate any classes that can be thrown as exceptions. Throwable objects can be divided into two types (derived from Throwable inheritance ):

Error:Used to indicate Compilation Time and system errors (generally do not care)

Exception:Is the basic type that can be thrown. Exception type exceptions may be thrown in Java class libraries, user methods, and runtime faults. Therefore, we need to care about this.

If an Exception occurs, we must capture or throw it.

 

 

There is a special case:RuntimeException

It is very troublesome to check all input references as follows.

If (t = null) throw new NullPointerException ();

Therefore, some exceptions (runtime exceptions) do not need to be detected. They are automatically detected and thrown out. If we do not capture it, The RuntimeException exception will go through all the execution paths to the main () method, and call the abnormal printStackTrace () method before the program exits.

In case of a common exception, the exception must be caught or thrown using the throws Declaration on the method in which it is located. In case of a runtime exception, the exception can not be captured, you do not need to declare the thrown exception in the method.

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.