How to handle exceptions in JAVA? What are the meanings of the keywords throws, throw, try, catch, and finally? Can an exception be thrown in the try block ?,

Source: Internet
Author: User

How to handle exceptions in JAVA? What are the meanings of the keywords throws, throw, try, catch, and finally? Can an exception be thrown in the try block ?,

Java uses object-oriented methods to handle exceptions, classify 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 one party
When an exception occurs, an exception object is thrown. The object contains the exception information.
Obtain the exception and handle it. Java exception handling is implemented through five keywords: try, catch, throw,
Throws and finally.
Generally, a program is executed using try. If an exception occurs, the system throws an exception,
At this time, you can catch it by its type, or finally (finally) it is processed by the default processor. Use
Try to specify a program to prevent all "exceptions. The catch clause should be specified immediately after the try program.
The type of the "exception" you want to capture. Throw statements are used to explicitly throw an "exception ". Throws is used to indicate
Various "exceptions" that a member function may throw ". Finally ensures that a piece of code is executed no matter what "exception" occurs.
Code. You can write a try statement outside a member function call, and write another try statement inside the member function.
Statement to protect other code. Every time a try statement is encountered, the framework of "exception" is placed on the stack until all try
The statement is complete. If the next try statement does not process an "exception", the stack will be opened
There is a try statement to handle this "exception"

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.