Java uses an object-oriented approach for exception handling, classifies various exceptions, and provides a good
Interface.
In Java, each exception is an object, which is an instance of the Throwable class or other subclass. When a party
Method throws an exception object, which contains the exception information, the method that calls this object can catch
Get this exception and deal with it. Java exception handling is achieved by 5 key words: try, catch, throw,
Throws and finally.
In general, a try to execute a program, if an exception occurs, the system throws (throws) an exception,
At this point you can catch (catch) it by its type, or finally (finally) be handled by the default processor. Use
Try to specify a piece of program that prevents all "exceptions". Immediately following the try program, you should include a catch clause to specify
The type of "exception" you want to capture. The throw statement is used to explicitly throw an "exception". Throws is used to mark a
The member functions may throw various "exceptions". Finally to make sure that a piece of code is executed no matter what "exception" is
Code. You can write a try statement outside of a member function call and write another try inside the member function
Statement to protect other code. Whenever a try statement is encountered, the "exception" frame is placed on the stack until all the try
Statement is complete. If the next-level try statement does not handle an "exception", the stack expands until it encounters
There is a try statement that handles this "exception"
How does the JAVA language perform exception handling, keywords: what does throws,throw,try,catch,finally mean? Can I throw an exception in a try block?