Java exception handling after-school programs often appear in the summary

A, JDK common abnormality

1, common abnormal summary map

 

 

 

 2, java exception Categories

Throwable class has two direct subclasses:

 

 

 (1) Exception: the problem arises that can be captured

(2) Error: System Error, typically handled by the JVM

 

 

 

3, caught exception classification

(1) Check Exception: exception classes derived from Exception must be caught or thrown Again

(2) Runtime exception: derived from RuntimeException exception classes. Use the throw statement can throw this exception object at any time to throw new ArithmeticException (...);

 

Second, the cause of the disturbance of

1, the user enters invalid data.

2, to open the file does not exist.

3, a network communication connection is interrupted

4, JVM memory overflow

 

Three, java program several common abnormal and cause of this exception occurs

Third, several common anomalies and their causes

1, java.lang.NullpointerException (NullPointerException)

Cause: This exception often encountered, unusual because the program a null pointer, that the program calls uninitialized object or the object does not exist.

Create objects often appear in the calling code array, such as uninitialized objects or pictures to create a path error, and so on. An array of code

The null pointer is initialized and the initialization of array elements of the array, confused. Initialize the array is an array of distribution space, and the array elements

Initialization is assigned to the array element of the initial value of

2, java.lang.NumberFormatException (character string into digital abnormal)

Reason: when trying to convert a digital data of type String Specifies the type of string, but does not meet the requirements of numerical data, the heterologous throws

often. For example, data of type String "123456" is converted into numerical data, can be converted. But if the String data type contains

Non-numeric characters, such as 123 * 56, then an exception will be when converted into a numerical type. The system will catch this exception, and processed


The reason: because the name and path of the class is incorrect, usually by a string program tries to load a class, it might throw an exception. E.g:

An exception occurred (when) call Class.forName (), or call ClassLoad of finaSystemClass (), or LoadClass

Guess you like

Origin www.cnblogs.com/yang2000/p/11764200.html