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?

Source: Internet
Author: User

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?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.