Exceptions and Errors in Java

Source: Internet
Author: User

the difference between an exception and an error. Exception: In Java, the error of the program is mainly a syntax error and semantic error, a program in the compilation and runtime errors we call the exception, it is a VM (virtual machine) notify you a way, in this way, the VM let you know,
You (the developer) have made a mistake and now have a chance to modify it. Exception classes are used in Java to represent exceptions, and different exception classes represent different exceptions. But all exceptions in Java have a base class, called exception. Error: It refers to a serious problem that a reasonable application cannot intercept. Most of them are abnormal situations. The error is a failure of the VM (although it can be any system-level service). So, mistakes are hard to deal with,
It is not common for developers to handle these errors. For example, memory overflow; As with exceptions, the error class is used in Java to represent errors, and different error classes represent different errors. But all the errors in Java have a base class called error. In conclusion , we can know that the most essential difference between the anomaly and the error is that the exception can be handled by the developer and the error is the system originally brought, the general can not deal with or need our programmer to deal with. exception Classification in Java is divided into two major categories: Compiler exception and run exception running exception is runtimeexception; All the rest of the compiler exception in Java exception exception and error errors in Java have a common parent class throwable. Three, runtimeexception several sub-categories of the specific introduction
1, java.lang.ArrayIndexOutOfBoundsException array index out-of-bounds exception. Thrown when the index value of an array is negative or greater than or equal to the size of the arrays. 2, java.lang.ArithmeticException arithmetic condition is abnormal. For example: integers except 0. 3, java.lang.NullPointerException null pointer exception. This exception is thrown when an app tries to use null where the object is required. Example: Invoking an instance method of a null object, accessing the properties of a null object, calculating the length of a null object, throwing null with a throw statement, and so on4, Java.lang.ClassNotFoundException cannot find a class exception. This exception is thrown when an application attempts to construct a class based on a class name in string form, and when a class file of the corresponding name is not found after traversing Classpah.

Exceptions and Errors in Java

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.