JAVA common exception handling of the project 1

Common exception handling of Java project

. 1, java.lang.NullPointerException (NullPointerException)

It calls uninitialized object or the object does not exist. Often creating a picture, call the array of these operations, such as uninitialized pictures, or pictures to create a path of error, and so on. Null pointer array operation occurs, i.e., the initialization and the initialization of the array elements of the array confused. Initialize the array is allocated space for an array of needs, and the array after initialization, whose elements are not instantiated, is still empty, so it needs to initialize each element (if you want to call it).

 

2, a java.lang.ClassNotFoundException (specified class does not exist)

Here the main consideration about the name and path are correct to class, usually possible exception is thrown when a program attempts to load a class by string. For example: calling Class.forName (); or by calling ClassLoad of finaSystemClass (); or LoadClass ();

 

. 3, java.lang.NumberFormatException (string converted to digital abnormal)

When trying to convert a String number specified type, and the string does not satisfy the requirements of the format of the digital type, out of the anomaly. As now speak when character data "123456" is converted into numeric data, allowing of. However, if the character data type contains a non-numeric characters, such as 56 # 123, then an exception will be when converted into a numerical type. The system will catch this exception and processed.

 

. 4, a java.lang.IndexOutOfBoundsException (array subscript bounds exception)

An array index value or a character string is not a call to see beyond the scope of the array, in general, display (i.e., directly labeled with a constant current) call is not easy with such errors, but implicit (i.e., with a variable indicates standard) calls often wrong, there is a situation, the array is the length of the program is defined by a certain method of decision, not prior notice, this time to check out the length of the array, in order to avoid this anomaly.

 

. 5, a java.lang.IllegalArgumentException (parameter error method)

For example g.setColor (int red, int, int blue green) this method of three values, if there are more than 255 will also appear this exception, so if it is found that abnormal, we need to do is rush to check method parameters passed in the call is not an error.

 

6, java.lang.IllegalAccessException (no access)

When an application to call a class, but that is the current method does not have access to this class there will be the exception. In the case of the program with a Package to pay attention to this anomaly.

 

7, java.lang.ArithmeticException (math abnormal)

When the arithmetic appeared in such operations will be divided by zero out such an exception.

 

. 8, a java.lang.ClassCastException (data type conversion exception)

When an object will attempt to enforce downcast, but the object and its non-convertible and non-convertible subclass instance throws the exception, as the following code.

Object obj = new Integer(0);

String str = obj;

 

9, java.lang.FileNotFoundException (file not found exception)

When the program tries to open a file that does not exist to read and write will trigger the exception. The exception is thrown by the constructor statement FileInputStream, FileOutputStream, RandomAccessFile, even if the file operation exists, but for some reason inaccessible, such as opening a read-only file for writing, these constructors still throws an exception.

 

10, java.lang.ArrayStoreException (Abnormal storage array)

When you try to type object type is not compatible with a deposit Object [] array will throw an exception when, as

Object[] obj = new String[3]

obj[0] = new Integer(0);

 

. 11, java.lang.NoSuchMethodException (method there is no abnormality)

Program tries to create an object by reflection when accessing (read or modify) a method, but this method does not exist will throw an exception.

 

12, java.lang.EOFException (file ends abnormally)

When the program encounters the end of a file or stream during input, an exception is thrown. Thus exception for checking whether the end of the file or stream

 

13 is, java.lang.InstantiationException (Example Exception)

Raised when trying to newInstance Class of () method creates an instance of a class, but was unable to create the object by the constructor. Class object represents an abstract class, an interface, an array type, base type. The Class class indicates no corresponding constructor.

 

14, java.lang.InterruptedException (aborted abnormal)

Thrown when a thread in a long time waiting, sleeping, or otherwise paused state, at a time when the other thread to terminate the thread by interrupt method of Thread.

 

15, java.lang.CloneNotSupportedException (clone does not support exception)

When not implement or does not support Cloneable interface cloning method, call its clone () method out of the anomaly.

 

16, java.lang.OutOfMemoryException (out of memory error)

This error is thrown when the available memory is not sufficient to make the Java virtual machine is assigned to an object.

 

17, java.lang.NoClassDefFoundException (class definition not found error)

This error is thrown when the Java Virtual Machine or the class loader tries to instantiate a class, but can not find the definition of the class.

 

18, SecturityException (security breach abnormal)

 

. 19, SQLException (abnormal operation database)

 

20 is, IOException (O abnormal)

 Exception the exception of a branch, usually occurs on the data read and write files.

21 is, a SocketException (communication abnormality)

 

22, java.lang.Error (error)

Wrong, wrong is the base class for identifying serious running problems, which usually describe some anomalies should not be captured by the application.

The reason: access to external resources on the system, shut down operations not implemented, resulting in wasting a lot of external resources may eventually cause the system to not function properly; external system access; too many external resources on the system shut down access times, the external system can not handle normal anomalies resources appear.

Solution: prior to access external resources, first checks the resources (e.g., database) whether the normal connection or operation; access to external resources, if the connection must be the closing operation, and only once the closing operation; as far as possible in the same operation sharing external resources, in order to reduce the operational waste of resources, improve the efficiency of the program.

 

 

 

. 1, java.lang.NullPointerException (NullPointerException)

It calls uninitialized object or the object does not exist. Often creating a picture, call the array of these operations, such as uninitialized pictures, or pictures to create a path of error, and so on. Null pointer array operation occurs, i.e., the initialization and the initialization of the array elements of the array confused. Initialize the array is allocated space for an array of needs, and the array after initialization, whose elements are not instantiated, is still empty, so it needs to initialize each element (if you want to call it).

 

2, a java.lang.ClassNotFoundException (specified class does not exist)

Here the main consideration about the name and path are correct to class, usually possible exception is thrown when a program attempts to load a class by string. For example: calling Class.forName (); or by calling ClassLoad of finaSystemClass (); or LoadClass ();

 

. 3, java.lang.NumberFormatException (string converted to digital abnormal)

When trying to convert a String number specified type, and the string does not satisfy the requirements of the format of the digital type, out of the anomaly. As now speak when character data "123456" is converted into numeric data, allowing of. However, if the character data type contains a non-numeric characters, such as 56 # 123, then an exception will be when converted into a numerical type. The system will catch this exception and processed.

 

. 4, a java.lang.IndexOutOfBoundsException (array subscript bounds exception)

An array index value or a character string is not a call to see beyond the scope of the array, in general, display (i.e., directly labeled with a constant current) call is not easy with such errors, but implicit (i.e., with a variable indicates standard) calls often wrong, there is a situation, the array is the length of the program is defined by a certain method of decision, not prior notice, this time to check out the length of the array, in order to avoid this anomaly.

 

. 5, a java.lang.IllegalArgumentException (parameter error method)

For example g.setColor (int red, int, int blue green) this method of three values, if there are more than 255 will also appear this exception, so if it is found that abnormal, we need to do is rush to check method parameters passed in the call is not an error.

 

6, java.lang.IllegalAccessException (no access)

When an application to call a class, but that is the current method does not have access to this class there will be the exception. In the case of the program with a Package to pay attention to this anomaly.

 

7, java.lang.ArithmeticException (math abnormal)

When the arithmetic appeared in such operations will be divided by zero out such an exception.

 

. 8, a java.lang.ClassCastException (data type conversion exception)

When an object will attempt to enforce downcast, but the object and its non-convertible and non-convertible subclass instance throws the exception, as the following code.

Object obj = new Integer(0);

String str = obj;

 

9, java.lang.FileNotFoundException (file not found exception)

When the program tries to open a file that does not exist to read and write will trigger the exception. The exception is thrown by the constructor statement FileInputStream, FileOutputStream, RandomAccessFile, even if the file operation exists, but for some reason inaccessible, such as opening a read-only file for writing, these constructors still throws an exception.

 

10, java.lang.ArrayStoreException (Abnormal storage array)

When you try to type object type is not compatible with a deposit Object [] array will throw an exception when, as

Object[] obj = new String[3]

obj[0] = new Integer(0);

 

. 11, java.lang.NoSuchMethodException (method there is no abnormality)

Program tries to create an object by reflection when accessing (read or modify) a method, but this method does not exist will throw an exception.

 

12, java.lang.EOFException (file ends abnormally)

When the program encounters the end of a file or stream during input, an exception is thrown. Thus exception for checking whether the end of the file or stream

 

13 is, java.lang.InstantiationException (Example Exception)

Raised when trying to newInstance Class of () method creates an instance of a class, but was unable to create the object by the constructor. Class object represents an abstract class, an interface, an array type, base type. The Class class indicates no corresponding constructor.

 

14, java.lang.InterruptedException (aborted abnormal)

Thrown when a thread in a long time waiting, sleeping, or otherwise paused state, at a time when the other thread to terminate the thread by interrupt method of Thread.

 

15, java.lang.CloneNotSupportedException (clone does not support exception)

When not implement or does not support Cloneable interface cloning method, call its clone () method out of the anomaly.

 

16, java.lang.OutOfMemoryException (out of memory error)

This error is thrown when the available memory is not sufficient to make the Java virtual machine is assigned to an object.

 

17, java.lang.NoClassDefFoundException (class definition not found error)

This error is thrown when the Java Virtual Machine or the class loader tries to instantiate a class, but can not find the definition of the class.

 

18, SecturityException (security breach abnormal)

 

. 19, SQLException (abnormal operation database)

 

20 is, IOException (O abnormal)

 Exception the exception of a branch, usually occurs on the data read and write files.

21 is, a SocketException (communication abnormality)

 

22, java.lang.Error (error)

Wrong, wrong is the base class for identifying serious running problems, which usually describe some anomalies should not be captured by the application.

The reason: access to external resources on the system, shut down operations not implemented, resulting in wasting a lot of external resources may eventually cause the system to not function properly; external system access; too many external resources on the system shut down access times, the external system can not handle normal anomalies resources appear.

Solution: prior to access external resources, first checks the resources (e.g., database) whether the normal connection or operation; access to external resources, if the connection must be the closing operation, and only once the closing operation; as far as possible in the same operation sharing external resources, in order to reduce the operational waste of resources, improve the efficiency of the program.

 

 

 

Guess you like

Origin www.cnblogs.com/022414ls/p/11780930.html