Common exception classes in Java

Source: Internet
Author: User
Tags instance method

1. java.lang.NullPointerException This exception is certainly often encountered, the abnormal explanation is "the program encountered a null pointer", simply called an uninitialized object or a nonexistent object, this error often appears in the creation of pictures, Call array in these operations, the slice is not initialized, or the picture is created with a path error, and so on. A null pointer appears in an array operation, and in many cases is a common mistake made by friends who are just beginning to learn programming, which confuses the initialization of arrays and the initialization of the array elements. The initialization of an array is the space required for the allocation of arrays, and the initialized array, where the elements are not instantiated, are still empty, so you also need to initialize each element (if it is to be called).
2. java.lang.ClassNotFoundException This anomaly is a lot of programmers developed in the development environment, such as JB, put the package under JB under the WTK to compile the frequently occurring problem, the explanation of the exception is "The specified class does not exist", Here is the main consideration of the class name and path is correct, if the package is done under the JB, is usually the default plus packages, so go to the WTK to pay attention to the package path Add.
3. Java.lang.arithmeticexception the explanation of this anomaly is "mathematical operation Anomaly", such as the program appears divided by 0 such an operation will be such an exception, for this anomaly, we have to check the program of their own procedures involved in the mathematical operation of the place, The formula is not wrong.
4. Java.lang.arrayindexoutofboundsexception This exception is believed many friends also frequently encountered, the abnormal explanation is "the array subscript crosses the bounds", now most of the procedure has the operation of the array, therefore must examine carefully in the call arrays, See if the subscript you call is outside the range of the array, in general, the display (that is, directly with the constant subscript) call is not easy to make such a mistake, but the implicit (that is, the use of variable-subscript) calls are often wrong, there is another case, the length of the array defined in the program is determined by some specific method, Not in advance, this is a good time to look at the length of the array to avoid this exception.
5. Java.lang.illegalargumentexception this exception is interpreted as "parameter error of the method", and many of the methods in the J2ME class library can cause such errors in some cases. For example, the volume adjustment method in the volume parameter if written as a negative number will appear this exception, such as G.setcolor (int red,int green,int Blue) This method of three values, if there are more than 255 of the exception will occur, so once you find this exception, All we have to do is go check it out. The parameter passing in the method call is not an error.
6. Java.lang.illegalaccessexception This exception is interpreted as "no access", which occurs when the application is calling a class, but the current method does not have access to the class. Be aware of this exception in cases where the package is used in the program.
There are many other exceptions, I will not enumerate, I would like to state that a qualified programmer, the program needs to have a good understanding of common problems and corresponding solutions, otherwise just stay in writing procedures and will not change the program, will greatly affect their own development. The full description of the exception is available in the API.

Arithmetic Exception class: Arithmeticexecption
Null pointer exception class: NullPointerException
Type cast Exception: ClassCastException
Array negative subscript exception: Negativearrayexception
Array subscript out-of-bounds exception: ArrayIndexOutOfBoundsException
Violation of security principle exception: Secturityexception
File ended exception: Eofexception
File not found exception: FileNotFoundException
string conversion to numeric exception: NumberFormatException
Manipulating Database Exceptions: SQLException
Input/Output exception: IOException
Method not found exception: Nosuchmethodexception
Java.lang.AbstractMethodError
Abstract method Error. Thrown when an application tries to invoke an abstract method.
Java.lang.AssertionError
Assertion is wrong. Used to indicate a condition in which an assertion failed.
Java.lang.ClassCircularityError
Class loop-dependent error. When a class is initialized, the exception is thrown if a circular dependency between the classes is detected.
Java.lang.ClassFormatError
The class format is incorrect. Thrown when a Java virtual machine attempts to read a Java class from a file and detects that the contents of the file do not conform to the valid format of the class.
Java.lang.Error
Error. is the base class for all errors that identify serious program run issues. These problems often describe anomalies that should not be captured by the application.
Java.lang.ExceptionInInitializerError
Initialization program error. Thrown when an exception occurs during the execution of a static initializer for a class. Static initializers refer to static statement segments that are included directly in the class.
Java.lang.IllegalAccessError
Illegal access error. This exception is thrown when an application attempts to access, modify, or invoke the domain (field) of a class or call its methods, but violate the visibility declaration of a domain or method.
Java.lang.IncompatibleClassChangeError
Incompatible class change error. This exception is thrown when an incompatible change is made to the class definition on which the method being executed depends. This error is easily thrown when you modify the declaration definition for some classes in your app without recompiling the entire application.
Java.lang.InstantiationError
Instantiation of the error. This exception is thrown when an application attempts to construct an abstract class or interface through Java's new operator.
Java.lang.InternalError
Internal error. Used to indicate an internal error occurred with the Java virtual machine.
Java.lang.LinkageError
Link error. The error and all its subclasses indicate that a class depends on another class, and after that class is compiled, the dependent class changes its class definition without recompiling all of the classes, which in turn raises the error condition.
Java.lang.NoClassDefFoundError
Class definition error not found. This error is thrown when a Java virtual machine or class loader attempts to instantiate a class and cannot find the definition of the class.
Java.lang.NoSuchFieldError
There are no errors in the domain. This error is thrown when an application attempts to access or modify a domain of a class that does not have a definition of that domain in the definition of that class.
Java.lang.NoSuchMethodError
Method has no errors. This error is thrown when an application attempts to invoke a method of a class that does not have the definition of the method in the definition of the class.
Java.lang.OutOfMemoryError
Insufficient memory error. This error is thrown when the available memory is insufficient for a Java virtual machine to be assigned to an object.
Java.lang.StackOverflowError
Stack overflow error. This error is thrown when the hierarchy of an application recursive call is too deep to cause a stack overflow.
Java.lang.ThreadDeath
The thread ends. This error is thrown when the stop method of the thread class is called to indicate the end of the thread.
Java.lang.UnknownError
Unknown error. Used to indicate a situation in which a Java virtual machine has an unknown critical error.
Java.lang.UnsatisfiedLinkError
An unsatisfied link error. Thrown when a Java virtual machine does not find a class that is declared as a native language definition of the native method.
Java.lang.UnsupportedClassVersionError
Unsupported class version error. This error is thrown when the Java Virtual machine attempts to read a class file, but discovers that the primary and minor version number of the file is not supported by the current Java virtual machine.
Java.lang.VerifyError
Validation error. This error is thrown when the validator detects an internal incompatibility or security issue in a class file.
Java.lang.VirtualMachineError
Virtual machine error. A condition that indicates that the virtual machine is compromised or that the resource required to continue performing the operation is insufficient.
Java.lang.ArithmeticException
Arithmetic condition exception. For example: integers except 0.
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.
Java.lang.ArrayStoreException
Array storage exception. Thrown when a non-array declaration type object is placed into the array.
Java.lang.ClassCastException
Class shape exception. Assuming that there are classes A and B (A is not a parent or subclass of B), and O is an instance of a, the exception is thrown when an O is forced to be constructed as an instance of Class B. This exception is often called coercion type conversion exception.
Java.lang.ClassNotFoundException
The class exception could not be found. 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.
Java.lang.CloneNotSupportedException
Cloning exceptions are not supported. When the Cloneable interface is not implemented or the Clone method is not supported, the exception is thrown by calling its clone () method.
Java.lang.EnumConstantNotPresentException
An enumeration constant does not have an exception. This exception is thrown when an application attempts to access an enumeration object by name and enumeration type, but the enumeration object does not contain a constant.
Java.lang.Exception
The root exception. Used to describe what the application wants to capture.
Java.lang.IllegalAccessException
An illegal access exception. This exception is thrown when an application attempts to create an instance of a class by reflection, accesses the class property, calls the class method, and then cannot access the definition of a class, property, method, or constructor method.
Java.lang.IllegalMonitorStateException
Violations of the monitoring State anomalies. This exception is thrown when a thread tries to wait for a monitor that does not own the object (O) or notifies other threads to wait for the object (O).
Java.lang.IllegalStateException
An abnormal state of law. This exception is thrown when the Java environment and the application are not already in the legal invocation state of a method, and the method is called.
Java.lang.IllegalThreadStateException
An illegal thread state exception. An exception is thrown when the county seat is not in the legal calling state of a method and the method is called.
Java.lang.IndexOutOfBoundsException
Index out-of-bounds exception. This exception is thrown when an index value that accesses a sequence is less than 0 or greater than or equal to the sequence size.
Java.lang.InstantiationException
Instantiate the exception. This exception is thrown when an attempt is made to create an instance of a class through the newinstance () method, which is an abstract class or interface.
Java.lang.InterruptedException
Aborted exception. This exception is thrown when a thread is in a long wait, hibernate, or other paused state while another thread terminates the thread through the interrupt method of the thread.
Java.lang.NegativeArraySizeException
The array size is a negative value exception. This exception is thrown when an array is created with a negative size value.
Java.lang.NoSuchFieldException
No exception exists for the property. This exception is thrown when a property that does not exist for a class is accessed.
Java.lang.NoSuchMethodException
Method has no exception. This exception is thrown when a non-existent method of a class is accessed.
Java.lang.NullPointerException
Null pointer exception. This exception is thrown when an app tries to use null where the object is required. For example: Call an instance method of a Null object, access the properties of a null object, evaluate the length of a null object, throw null with a throw statement, and so on.
Java.lang.NumberFormatException
Number format exception. This exception is thrown when an attempt is made to convert a string to the specified number type, and the string does not satisfy the format required by the number type.
Java.lang.RuntimeException
Run-time exception. is the parent class of exceptions that can be thrown during normal operation of all Java virtual machines.
Java.lang.SecurityException
Security exception. Thrown by the security manager to indicate an exception that violates the security situation.
Java.lang.StringIndexOutOfBoundsException
String index out of bounds exception. This exception is thrown when an index value is used to access a character in a string, and the index value is less than 0 or greater than or equal to the sequence size.
Java.lang.TypeNotPresentException
There is no exception for type.

Common exception classes 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.