In Java, errors are classified into two types based on the error nature: errors and exceptions.
In JavaProgramIf an exception occurs during execution, an exception object is generated. The generated exception object is passed to the Java runtime system. The exception generation and submission process is called throw exception.
When the system obtains an exception object during Java runtime, it will trace back to the method call stack layer by layer to find the exceptionCode. After finding a method that can handle this type of exception, the runtime system submits the current exception object to this method for processing. This process is called catch exception.
All exceptions in Java are generated by the throwable class subclass, and all Exception classes are subclasses of the throwable class or subclass. The throwable class is the direct subclass of the object class, and the error class and the exception class are the two direct subclasses of the throwable class.
1. Error class
The error class includes some serious system errors that cannot be processed by programs, such as memory overflow, virtual machine errors, and stack overflow. This type of error is generally related to hardware and has nothing to do with the program itself. It is usually handled by the system and cannot be captured or processed by the program itself.
The common subclass 1 of the error class is shown in.
Figure1 errorCommon subclass of A Class
2. exception class
Some exceptions cannot be anticipated during programming, such as exceptions of interruptions or illegal access. To ensure program robustness, Java requires that these exceptions be captured and processed.
The common subclass 2 of the exception class is shown in.
Figure2 exceptionCommon subclass of A Class
3. runtimeexception class
The runtimeexception class is a subclass of the exception class. The common subclass 3 of the runtimeexception class is shown in.
Figure3 runtimeexceptionCommon subclass of A Class