Instance parsing try {} catch{} action _java

Source: Internet
Author: User

Today, a small partner to my message to ask, try{...} catch () {...} What is the meaning? What's it for?

To put it simply, they're used to catch anomalies.

Let's go through an example to explain in detail

 Try
 {
  Image img=image.createimage ("/image.png");
  Alert.setimage (IMG);
 } catch (java.io.IOException e)
 {
   System.out.println ("Error");
 }

Image img=image.createimage ("/image.png");
If the file is not found, there will be an error
So the way to handle this anomaly is to use the above method
Catch is to catch the exception and then handle the exception, here is the output error

Other words
It executes the program in the try bracket first:
Image img=image.createimage ("/image.png");
Alert.setimage (IMG);
If there is a mistake inside, jump directly into the catch block, throw System.out.println ("error"); This sentence tells you there are errors in the try Brackets

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.