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