Common exceptions in Java projects

1. java.lang.nullpointerexception
  This exception must be encountered frequently. The explanation of the exception is "the program encountered a null pointer", which simply means that an uninitialized object or a non-existing object is called. This error often occurs when creating pictures, calling arrays In these operations, for example, the image is not initialized, or the path is wrong when the image is created, etc. Null pointers appear in array operations. In many cases, it is a common mistake made by friends who have just started learning programming, that is, confusing the initialization of arrays with the initialization of array elements. The initialization of the array is to allocate the required space for the array, and the elements of the initialized array are not instantiated and are still empty, so each element needs to be initialized (if it is to be called)

  2. java.lang.classnotfoundexception
  This exception is a common problem for many programmers who originally developed in development environments such as jb, and compiles packages under jb under wtk. The explanation of the exception is "the specified class does not exist". Here we mainly consider the class Whether the name and path are correct, if the package is made under jb, the package is usually added by default, so after going to wtk, pay attention to adding the path of the package.

  3. java.lang.arithmeticexception
  The explanation of this exception is "mathematical operation exception". For example, an operation such as division by zero occurs in the program. Such an exception will occur. For this kind of exception, everyone should carefully check the place where mathematical operations are involved in your program. Is the formula wrong?

  4. java.lang.arrayindexoutofboundsexception
  I believe that many friends have encountered this exception frequently. The explanation of the exception is "array subscript out of bounds". Now most programs have operations on arrays, so when calling arrays, you must carefully check to see the subscript you call. Is it beyond the scope of the array? Generally speaking, it is not easy to make such mistakes in explicit (that is, directly subscripting with constants) calls, but implicit (that is, using variables to indicate subscripting) calls often make mistakes, and there is another The situation is that the length of the array defined in the program is determined by some specific methods, 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's class library will cause such an error 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, g .setcolor(int red, int green, int blue) The three values ​​in this method, if there are more than 255, this exception will also occur, so once we find this exception, what we need to do is to quickly check the method call Is there an error in parameter passing?

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

  There are many other exceptions, I will not list them one by one, what I want to point out is that a qualified programmer needs to have a considerable understanding of common problems in the program and corresponding solutions, otherwise it will only stop at writing programs and If you don't change the program, it will greatly affect your own development. All instructions about exceptions can be found in the api.

Arithmetic exception class: ArithmeticExecption

Null pointer exception class: NullPointerException

Type casting exception: ClassCastException

Array negative subscript exception: NegativeArrayException

Array index out of bounds exception: ArrayIndexOutOfBoundsException

Security violation exception: SecurityException

End of file exception: EOFException

File not found exception: FileNotFoundException

String to Number Exception: NumberFormatException

Operation database exception: SQLException

Input and output exception: IOException

Method not found exception: NoSuchMethodException

java.lang.AbstractMethodError

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

java.lang.AssertionError

Assertion is wrong. Used to indicate an assertion failure condition.

java.lang.ClassCircularityError

Class circular dependency error. This exception is thrown when a circular dependency between classes is detected when initializing a class.

java.lang.ClassFormatError

Class is malformed. 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 a valid format for the class.

java.lang.Error

mistake. Is the base class for all errors and is used to identify serious program execution problems. These problems usually describe some anomalous situation that should not be caught by the application.

java.lang.ExceptionInInitializerError

Initializer error. Thrown when an exception occurs during the execution of a static initializer for a class. A static initializer is a static statement segment directly contained in a class.

java.lang.IllegalAccessError

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

java.lang.IncompatibleClassChangeError

Incompatible class change error. Thrown when an incompatible change has occurred to the class definition on which the method being executed depends on. Generally, this error is easily caused when the declaration definition of some classes in the application is modified without recompiling the entire application and running directly.

java.lang.InstantiationError

Instantiation error. Thrown when an application attempts to construct an abstract class or interface via 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, and after the class is compiled, the dependent class changes its class definition without recompiling all the classes, thus causing the error condition.

java.lang.NoClassDefFoundError

Class definition not found error. This error is thrown when the Java virtual machine or class loader attempts to instantiate a class and cannot find a definition for the class.

java.lang.NoSuchFieldError

Domain does not exist errors. This error is thrown when an application attempts to access or modify a field of a class that does not have a definition for that field in the class definition.

java.lang.NoSuchMethodError

There is no error in the method. Thrown when an application attempts to call a method of a class that does not have a definition for that method in the class's definition.

java.lang.OutOfMemoryError

Out of memory error. Thrown when there is insufficient memory available for the Java Virtual Machine to allocate to an object.

java.lang.StackOverflowError

stack overflow error. Thrown when an application is too deep in recursive calls to overflow the stack .

java.lang.ThreadDeath

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 mistake. Used to indicate that an unknown critical error has occurred in the Java Virtual Machine.

java.lang.UnsatisfiedLinkError

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

java.lang.UnsupportedClassVersionError

Unsupported class version error. This error is thrown when the Java virtual machine tries to read a class file, 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. Thrown when the validator detects an internal incompatibility or security issue in a class file.

java.lang.VirtualMachineError

Virtual machine error. Used to indicate that the virtual machine is destroyed or that the resources required to continue operations 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 into the array is negative or greater than or equal to the size of the array.

java.lang.ArrayStoreException

Array storage exception. Thrown when storing an object of a non-array declared type into an array.

java.lang.ClassCastException

The class shape is abnormal. Suppose there are classes A and B (A is not a parent or subclass of B), and O is an instance of A, then this exception is thrown when O is forced to be constructed as an instance of class B. This exception is often referred to as a cast exception.

java.lang.ClassNotFoundException

Class Exception not found. This exception is thrown when the application tries to construct a class based on the class name in string form and cannot find a class file with the corresponding name after traversing the CLASSPAH.

java.lang.CloneNotSupportedException

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

java.lang.EnumConstantNotPresentException

There are no exceptions for enum constants. Thrown when an application attempts to access an enumeration object by 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 an application attempts to create an instance of a class, access properties of the class, and call methods of the class through reflection, but cannot access the definition of the class, properties, methods, or constructors at that time.

java.lang.IllegalMonitorStateException

The illegal monitoring status is abnormal. Thrown when a thread attempts to wait on a monitor for an object (O) that it does not own, or to notify other threads to wait on the monitor for that 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 yet in the legal calling state of the method.

java.lang.IllegalThreadStateException

Illegal thread state exception. When the county town is not in the legal calling state of a method and the method is called, an exception is thrown.

java.lang.IndexOutOfBoundsException

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

java.lang.InstantiationException

instantiation exception. This exception is thrown when trying 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-term waiting, sleeping or other suspended state, and other threads terminate the thread through the interrupt method of Thread.

java.lang.NegativeArraySizeException

Array size is negative exception. Thrown when creating an array with a negative size value.

java.lang.NoSuchFieldException

Property does not exist exception. Thrown when accessing a nonexistent property of a class.

java.lang.NoSuchMethodException

There is no exception to the method. Thrown when a non-existent method of a class is accessed.

java.lang.NullPointerException

Null pointer exception. Thrown when an application attempts to use null where an object is required. For example: calling the instance method of the null object, accessing the properties of the null object, calculating the length of the null object, using the throw statement to throw null and so on.

java.lang.NumberFormatException

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 required format of the numeric type.

java.lang.RuntimeException

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

java.lang.SecurityException

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

java.lang.StringIndexOutOfBoundsException

String index out of bounds exception. Thrown when accessing a character in a string using an index value that is less than 0 or greater than or equal to the sequence size.

java.lang.TypeNotPresentException

Type does not exist exception. When the application tries to
References:
http://zhidao.baidu.com/question/86639626.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324744796&siteId=291194637