As can be seen from the inheritance architecture diagram of the exception class: the Exception class extends several subclasses, of which IOException and RunntimeException are the two more commonly used ones.
It is customary to refer to the Error and Exception classes as exception classes, but they are essentially different. The Error class is specially used to deal with errors that seriously affect the running of the program. However, usually programmers do not design program code to catch this kind of error. The reason is that even if it is caught, it cannot be handled appropriately. For example, when a JAVA virtual machine error occurs, It is a kind of Error.
Different from the Error class, the Exception class contains general exceptions. These exceptions can usually be properly handled after being caught to ensure that the program continues to run. For example, the ArrayIndexOutOfBoundsException captured in TestException7_2 is Belongs to this anomaly.
RunntimeException Even if you do not write exception handling program code, you can still compile successfully, and this exception must occur when the program is running. For example: the index value of the array exceeds the range.
Different from RunntimeException, IOException must be written with exception handling program code. It is usually used to handle input/output related operations, such as file access, network connection, etc.
When an exception occurs, the statement code where the exception occurs will throw an instantiation object of the exception class. This object will then be matched with the type of the class in the catch statement, and then processed in the corresponding catch. .
Extended information:
Classification of Java exceptions:
Java standard pants have some built-in general exceptions, and these classes have Throwable as the top-level parent class.
Throwable derives the Error class and the Exception class.
Error: Instances of the Error class and its subclasses represent errors in the JVM itself. Errors cannot be handled by programmers through code, and Errors rarely occur. Therefore, programmers should pay attention to various exception classes under the branch where Exception is the parent class.
Exception: Exception and its subclasses represent various unexpected events sent when the program is running. It can be used by the Java exception handling mechanism and is the core of exception handling.
Reference: Baidu Encyclopedia-Abnormal
In the seedling stage, the topmost growth point of Yunxianghua bonsai was removed and more branches grew. Prune the branches that are too dense, too prosperous, d