Common exception classes in Java

1. java. lang.nullpointerexception

We must often encounter this exception. The explanation of the exception is that "the program encounters a null pointer". In short, it calls an uninitialized object or a nonexistent object. This error often occurs in the operations of creating pictures and calling arrays, such as uninitialized pictures or path errors during picture creation. In many cases, the occurrence of null pointers in array operations is a common mistake made by some friends who are just beginning to learn programming, that is, the initialization of arrays and the initialization of array elements are confused. Array initialization is to allocate space to the array. After initialization, the elements in the array are still empty without instantiation, so each element needs to be initialized (if called)

2. java. lang.classnotfoundexception

This exception is a common problem that many programmers originally developed in JB and other development environments compile packages under JB under WTK. The explanation of the exception is that "the specified class does not exist". Here, we mainly consider whether the class name and path are correct. If the package is made under JB, package is generally added by default, So after you go to WTK, you should add the path of the package.

3. java. lang.arithmeticexception

The explanation of this exception is "mathematical operation exception". For example, if there is an operation such as dividing by zero in the program, such an exception will occur. For this exception, we should carefully check whether there is something wrong with the formula involved in the mathematical operation in our program.

4. java. lang.arrayindexoutofboundsexception

I believe many friends have often encountered this exception. The explanation of the exception is "array subscript out of bounds". Now most programs operate on arrays. Therefore, when calling arrays, you must carefully check whether the subscript you call exceeds the range of arrays. Generally speaking, It is not easy to make such an error when calling display (i.e. directly using constants as subscripts), but implicit (i.e. using variables as subscripts) calls often make errors. There is another case that the length of the array defined in the program is determined by some specific methods and is not declared in advance. At this time, it is best to check the length of the array first to avoid this exception.

5. java. lang.illegalargumentexception

The explanation of this exception is "method parameter error". Many methods in J2ME class libraries will cause such errors in some cases. For example, if the volume parameter in the volume adjustment method is written as a negative number, this exception will occur. For example, if there are three values in the g. SetColor (int red, int green, int blue) method, this exception will also occur if it exceeds 255, Therefore, once this exception is found, what we need to do is to quickly check whether there is an error in the parameter passing in the method call.

6. java. lang.illegalaccessexception

The explanation of this exception is "no access permission". This exception occurs when the application wants to call a class, but the current method does not have access to the class. Pay attention to this exception when package is used in the program.

There are many other exceptions. I won't list them one by one. What I want to explain is that a qualified programmer needs to have a considerable understanding of the common problems in the program and corresponding solutions. Otherwise, it will greatly affect his own development if he just stays in writing the program without changing the program. All descriptions of exceptions can be found in the API.

Arithmetic exception class: arithmetics exception

Null pointer exception class: NullPointerException

Type cast exception: ClassCastException

Array negative subscript exception: negativearrayexception

Array subscript out of bounds exception: ArrayIndexOutOfBoundsException

Exception violating security policy: secturiyexception

File ended exception: eofexception

Exception not found in file: FileNotFoundException

String to number exception: numberformatexception

Operation database exception: sqlexception

Input / output exception: IOException

Method found no exception: nosuchmethodexception

java. lang.AbstractMethodError

Abstract method error. Thrown when an application attempts to call an abstract method.

java. lang.AssertionError

The assertion is wrong. Used to indicate the failure of an assertion.

java. lang.ClassCircularityError

Class circular dependency error. When initializing a class, this exception is thrown if circular dependencies between classes are detected.

java. lang.ClassFormatError

Class format error. Thrown when the 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

Wrong. Is the base class for all errors, which is used to identify serious program running problems. These problems usually 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 the static initialization program of a class. Static initializer refers to the static statement segment directly contained in the class.

java. lang.IllegalAccessError

Illegal access error. This exception is thrown when an application attempts to access, modify the field of a class or call its method, but violates the visibility declaration of the field or method.

java. lang.IncompatibleClassChangeError

Incompatible class change error. This exception is thrown when an incompatible change occurs to the class definition on which the method being executed depends. Generally, this error is easily caused when the declaration definition of some classes in the application is modified without recompiling the whole application and running directly.

java. lang.InstantiationError

Instantiation 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 that an internal error has occurred in the Java virtual machine.

java. lang.LinkageError

Link error. This error and all its subclasses indicate that a class depends on other classes. After the class is compiled, the dependent class changes its class definition without recompiling all classes, resulting in an error.

java. lang.NoClassDefFoundError

Class definition error not found. This error is thrown when the 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, and there is no definition of the domain in the definition of the class.

java. lang.NoSuchMethodError

Method has no errors. This error is thrown when an application attempts to call a method of a class, but the definition of the method does not exist in the definition of the class.

java. lang.OutOfMemoryError

Out of memory error. This error is thrown when the available memory is insufficient for the Java virtual machine to allocate to an object.

java. lang.StackOverflowError

Stack overflow error. This error is thrown when an application recursion call is too deep to cause stack overflow.

java. lang.ThreadDeath

End of thread. This error is thrown when the stop method of the thread class is called to indicate that the thread ends.

java. lang.UnkNownError

Unknown error. Used to indicate that an unknown critical error has occurred in the Java virtual machine.

java. lang.UnsatisfiedLinkError

Unsatisfied link error. Thrown when the Java virtual machine does not find a native language definition of a class declared as a native method.

java. lang.UnsupportedClassVersionError

Unsupported class version error. This error is thrown when the Java virtual machine attempts to read a class file from, but finds that the major and minor version numbers of the file are not supported by the current Java virtual machine.

java. lang.VerifyError

Validation error. This error is thrown when the verifier detects an internal incompatibility or security problem in a class file.

java. lang.VirtualMachineError

Virtual machine error. Used to indicate that the virtual machine is damaged or the resources required to continue the operation are insufficient.

java. lang.ArithmeticException

Arithmetic condition exception. For example: integer division by zero, etc.

java. lang.Arrayindexoutofboundsexception

Array index out of bounds exception. Thrown when the index value of the array is negative or greater than or equal to the array size.

java. lang.ArrayStoreException

Array storage exception. Thrown when a non array declaration type object is stored in an array.

java. lang.ClassCastException

Class shape exception. Assuming that there are classes a and B (a is not the parent or child of B) and O is an instance of a, this exception is thrown when o is forcibly constructed as an instance of class B. this exception is often called a cast exception.

java. lang.ClassNotFoundException

Class exception not found. This exception is thrown when the application attempts to construct a class according to the class name in string form, but cannot find the class file with the corresponding name after traversing the classpath.

java. lang.CloneNotSupportedException

Cloning exceptions are not supported. When the clonable interface is not implemented or the clone method is not supported, this exception is thrown when the clone () method is called.

java. lang.EnumConstantNotPresentException

Enumeration constant has no exception. This exception is thrown when an application attempts to access an enumeration object through name and enumeration type, but the enumeration object does not contain constants.

java. lang.Exception

Root exception. Used to describe what the application wants to capture.

java. lang.illegalaccessexception

Illegal access exception. This exception is thrown when the application attempts to create an instance of a class, access the properties of the class, and call the methods of the class through reflection, but cannot access the definitions of the class, properties, methods, or construction methods at that time.

java. lang.IllegalMonitorStateException

Illegal monitoring status is abnormal. This exception is thrown when a thread attempts to wait for a monitor of an object (o) that it does not own or notifies other threads to wait for the monitor of the object (o).

java. lang.IllegalStateException

Illegal status exception. This exception is thrown when the method is called in the Java environment and the application is not in the legal calling state of a method.

java. lang.IllegalThreadStateException

Illegal thread state exception. An exception is thrown when the method is called while it is not in the legal calling state of a method.

java. lang.indexoutofboundsexception

Index out of bounds exception. This exception is thrown when the index value accessing a sequence is less than 0 or greater than or equal to the sequence size.

java. lang.InstantiationException

Instantiation exception. This exception is thrown when an attempt is made to create an instance of a class that is an abstract class or interface through the newinstance () method.

java. lang.InterruptedException

Aborted exception. This exception is thrown when a thread is in a long wait, sleep or other suspended state, and other threads terminate the thread through the interrupt method of thread.

java. lang.NegativeArraySizeException

Exception when the array size is negative. This exception is thrown when an array is created with a negative size value.

java. lang.NoSuchFieldException

Property has no exception. This exception is thrown when a nonexistent property of a class is accessed.

java. lang.NoSuchMethodException

Method has no exception. This exception is thrown when a nonexistent method of a class is accessed.

java. lang.NullPointerException

Null pointer exception. This exception is thrown when an application attempts to use null where an object is required. For example, call the instance method of null object, access the properties of null object, calculate the length of null object, throw null with throw statement, etc.

java. lang.NumberFormatException

The number format is abnormal. This exception is thrown when an attempt is made to convert a string to the specified numeric type, and the string does not meet the format required by the numeric type.

java. lang.RuntimeException

Runtime exception. Is the parent class of all exceptions that can be thrown during normal operation of the Java virtual machine.

java. lang.SecurityException

Security exception. An exception thrown by the security manager to indicate a security violation.

java. lang.Stringindexoutofboundsexception

String index out of bounds exception. This exception is thrown when an index value is used to access characters 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. When the application tries to

Focus on popular foreign websites

facebook: http://www.fb-on.com

Facebook website: http://www.facebookzh.com

facebook: http://www.cn-face-book.com

youtube: http://www.youtubezh.com

twitter: http://www.twitterzh.com

The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. At the same time, I also hope to support a lot of programming tips!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>