Roles of try blocks in Java

Source: Internet
Author: User
From: Linux library -- http://doc.linuxpk.com/47317.html

If it is inside a method and throws an violation (or another method called inside the method produces an violation), the method exits during the violation. If you do not want a throw to exit the method, you can set a special code block inside the method to capture the violation. This is called "Try block", because you need to "try" various method calls in this place. A try block belongs to a common scope and starts with a try Keyword:

Try {

// Code that may cause violation

}

If you use a programming language that does not support violation control to fully check errors, you must use the settings and error detection code to enclose each method, even if the same method is called multiple times. After using the violation control technology, you can place everything in a try block to capture all the violations in the same location. This greatly simplifies our code and makes it easier to identify and read, because the goal of the Code itself will no longer be confused with complicated error checks.

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.