Common exceptions in Java

Source: Internet
Author: User

Java exception Classification
All exceptions are inherited from the java. lang. Throwable class.
Throwable has two direct subclasses: Error and Exception.
Exception
Exception allows you to use the class methods of any standard Java library, your own methods, and the base types thrown out of any exceptions during the runtime.
There are two types of Exceptions: RuntimeException and Checked Exceptions.
RuntimeException
RuntimeException is automatically handled by default. Therefore, you do not need to capture RuntimeException. However, in your own encapsulation, you may still need to throw a part of RuntimeException.
RuntimeException

Is the superclass that may throw exceptions during the normal operation of the Java Virtual Machine. RuntimeException that may be thrown but not captured during method execution

Any subclass of does not need to be in throws

Clause. (Java api)
It is uncheckedExcepiton.
Java. lang. ArithmeticException
Java. lang. ArrayStoreExcetpion
Java. lang. ClassCastException
Java. lang. EnumConstantNotPresentException
Java. lang. IllegalArgumentException
Java. lang. IllegalThreadStateException
Java. lang. NumberFormatException
Java. lang. IllegalMonitorStateException
Java. lang. IllegalStateException
Java. lang. IndexOutOfBoundsException
Java. lang. ArrayIndexOutOfBoundsException
Java. lang. StringIndexOutOfBoundsException
Java. lang. NegativeArraySizeException'
Java. lang. NullPointerException
Java. lang. SecurityException
Java. lang. TypeNotPresentException
Java. lang. UnsupprotedOperationException
CheckedException
All exceptions except runtimeException belong to checkedException, which are defined in the java. lang library. The Java compiler requires that the program capture or declare to throw this exception.
A method must use the throws statement to describe all checkedException that may be thrown but not captured in the declaration part of the method.
Java. lang. ClassNotFoundException
Java. lang. CloneNotSupportedException
Java. lang. IllegalAccessException
Java. lang. InterruptedException
Java. lang. NoSuchFieldException
Java. lang. NoSuchMetodException
Error
When an uncontrollable error occurs in a program, the common practice is to notify the user and stop the program execution.
Different from exceptions, the objects of errors and Their subclasses should not be thrown.
An Error is a subclass of Throwable, representing the Compilation Time and system errors. It is used to indicate serious problems that a reasonable application should not try to capture. Most of these errors are exception conditions. Although ThreadDeath Error is a "regular" condition, it is also a subclass of Error because most applications should not try to capture it.
During the execution of this method, you do not need to declare in its throws clause Any subclass of errors that may throw but cannot be captured, because these errors may no longer occur.
It is uncheckedExcepiton.

Author "life is a kind of practice"
 

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.