Java encapsulates all errors as an object with the root parent class Throwable

Source: Internet
Author: User
Tags throwable

Java encapsulates all errors as an object with the root parent class Throwable.

There are two subcategories of Throwable: Error and exception.

An Error object indicates a program error, which refers to the underlying, low-level, unrecoverable, critical error. At this point the program must exit because it has lost the physical environment necessary to run.

We cannot handle error errors because we are using the program to deal with errors, but the program has exited.

There are only exception objects (exceptions/exceptions) in the Throwable object that we can handle.

Exception has two sub-classes: Runtime Exception (Exception not checked)

Non-runtime exception (checked for exceptions)

(Note: Whether the exception is not checked or the check exception is not found at compile time, during compilation, the program's syntax error is checked, and the exception is the concept of a run-time program error.) )

In exception, all non-unchecked exceptions are checked for exceptions, no additional exceptions!!

The exception was not checked because the programmer did not perform the necessary checks because of his negligence and errors caused by the exception. Must be an exception within the virtual machine (such as a null pointer).

1  PackageTomtext;2 //the assignment between the test objects. 3  Public classtomtext_46 {4     inti;5      Public Static voidmain (String [] a) {6tomtext_46 n1=Newtomtext_46 ();7tomtext_46 n2=Newtomtext_46 ();8N1.i=9;9n2.i=47;TenSystem.out.println ("n1.i=" +n1.i+ "\t\t" + "n2.i=" +n2.i); Onen1=N2;  ASystem.out.println ("n1.i=" +n1.i+ "\t\t" + "n2.i=" +n2.i); -N1.i=27;  -System.out.println ("n1.i=" +n1.i+ "\t\t" + "n2.i=" +n2.i); the     } -  -}

Java encapsulates all errors as an object with the root parent class Throwable

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.