Exceptions are broadly divided into compiler exceptions and run exceptions, and if you compile exceptions with software development (such as Eclipse), you get reminders when you write code, and running exceptions need to be prompted at run time.
Here are a few common types of exceptions that make it easy to check for errors when they occur:
(1) Exception the root class of various anomalies
You can define an exception type as exception if you do not know where the exception will occur and you can be certain that an exception will occur in this place.
(2) ArithmeticException arithmetic arithmetic error exception
This exception is often encountered in arithmetic operations, and the common case is the exception thrown when the divisor is 0.
(3) Arrayindexofoutboundsexception array subscript out of bounds
When programming, remember that the subscript for the Java array starts at 0, the array subscript maximum is reduced by 1, such as arr[10], the last array element is arr[9], and arrayindexofoutboundsexception exception occurs if written arr[10].
(4) nullpointexception null pointer exception
This exception is the exception that is thrown for calling an uninitialized or undefined object.
(5) ClassNotFoundException cannot load the required classes
After the Java file is compiled, it may be necessary to move the. class file to a different folder, at which point the. class file should be noted to modify its path, or the classnotfoundexception exception will be thrown.
(6) Inputmismatchexception input data type does not match the desired type of exception
For example, if you need an int type, but you get a string type from the input box, the inputmismatchexception exception will be thrown.
(7) IllegalArgumentException method accepts illegal parameters
This is an incorrect parameter type in the incoming method, such as method plus (int a,int b), which appears when written as A.plus (1,a).
IllegalArgumentException exception.
(8) NumberFormatException string converted to numeric exception
The exception that occurs when the data type is cast, the string "123" is converted to the number 123 without an exception, but the string "[email protected]" is converted to type int to throw a classcastexception exception.
Common types of exceptions in Java