Java NOTES: Exceptions

Source: Internet
Author: User

Hierarchy of the Exception class

All exception classes are subclasses that inherit from the Java.lang.Exception class.

The Exception class is a subclass of the Throwable class. In addition to the exception class, Throwable also has a subclass error.

Java programs typically do not catch errors. Errors generally occur in the event of a serious failure, which is outside the scope of the Java program processing.

The error is used to indicate that a run-time environment has occurred.

For example, JVM memory overflows. In general, the program does not recover from the error.

The exception class has two primary subclasses: the IOException class and the RuntimeException class.

Exception Description
ArithmeticException This exception is thrown when an operating condition of an exception occurs. For example, an integer "divided by 0" throws an instance of this class.
ArrayIndexOutOfBoundsException The exception that is thrown when an array is accessed with an illegal index. If the index is negative or greater than or equal to the array size, the index is an illegal index.
Arraystoreexception The exception that is thrown when attempting to store an object of the wrong type to an array of objects.
ClassCastException This exception is thrown when an attempt is made to cast an object to a subclass that is not an instance.
IllegalArgumentException The exception thrown indicates that an invalid or incorrect parameter was passed to the method.
Illegalmonitorstateexception The exception thrown indicates that a thread has tried to wait on the object's monitor, or has attempted to notify other monitors that are waiting on the object and that it does not already have a monitor specified.
IllegalStateException The signal generated when a method is called at an illegal or inappropriate time. In other words, the Java environment or Java application is not in the proper state required by the requested operation.
Illegalthreadstateexception The exception that is thrown when the thread is not in the appropriate state required by the request operation.
Indexoutofboundsexception Indicates that a sorted index (for example, sorting an array, string, or vector) is out of range when thrown.
Negativearraysizeexception If the application attempts to create an array with a negative size, the exception is thrown.
NullPointerException This exception is thrown when an application tries to use the object where it is needed null
NumberFormatException This exception is thrown when an application attempts to convert a string to a numeric type, but the string cannot be converted to the appropriate format.
SecurityException An exception that is thrown by the security manager, indicating that there is a security violation.
Stringindexoutofboundsexception This exception is String thrown by the method, indicating that the index is either negative or exceeds the size of the string.
Unsupportedoperationexception The exception is thrown when the requested operation is not supported.
Exception Description
ClassNotFoundException When an application attempts to load a class, the corresponding class is not found, and the exception is thrown.
Clonenotsupportedexception ObjectThis exception is thrown when a method in the calling class clone clones an object, but the object's class cannot implement the Cloneable interface.
Illegalaccessexception When a class is denied access, the exception is thrown.
Instantiationexception Class newInstance This exception is thrown when an attempt is made to create an instance of a class using a method in the class, and the specified class object cannot be instantiated because it is an interface or an abstract class.
Interruptedexception One thread was interrupted by another thread, throwing the exception.
Nosuchfieldexception The requested variable does not exist
Nosuchmethodexception The requested method does not exist

Java NOTES: Exceptions

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.