Home>

Today, a friend asked me to leave a message and asked,What does try {...} catch () {...} mean?What is it used for?

Simply put, they are used to catch exceptions

Let us explain in detail through an example

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 cannot be found,It will go wrong

So to handle this exception error,Is using the above method

catch is catching exceptions,Then for exception handling,Here is the output error

In other words

It first executes the program in the try brackets:

image img=image.createimage ("/image.png");

alert.setimage (img);

If there are errors in it,Just jump directly into the catch block and throw system.out.println ("error");this sentence tells you that there is an error in the try brackets

  • Previous Summary of JavaScript date formatting methods
  • Next Recommend 10 awesome jQuery effects code