How the Java language handles exceptions, keywords: what does throws,throw,try,catch,finally mean? __java

Source: Internet
Author: User
Java makes exception handling through object-oriented method, classifies different kinds of anomalies, and provides good interface. In Java, each exception is an object, which is an instance of a Throwable class or other subclass. When a method has an exception, an exception object is thrown, which contains exception information, and the method that invokes the object can catch the exception and process it. Java exception handling is done with 5 keywords: try, catch, throw, throws, and finally. Typically, a try is used to execute a program, and if an exception occurs, the system throws (throws) an exception, at which point you can catch (catch) it by its type, or the last (finally) by the default handler. Use try to specify a piece of program to prevent all "exceptions". Immediately following the try program, you should include a catch clause to specify the type of "exception" you want to catch. The throw statement is used to explicitly throw an "exception". Throws is used to indicate a variety of "exceptions" that a member function might throw. Finally, a piece of code is executed to ensure that a piece of code executes whatever "exception" occurs. You can write a try statement outside of a member function call, and write another try statement inside the member function to protect other code. Whenever a try statement is encountered, the "exception" frame is placed on the stack until all the try statements are completed. If a try statement at the next level does not handle an "exception", the stack expands until it encounters a try statement that handles 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.