The role of Try catch in Java __java

Source: Internet
Author: User
Tags try catch

Http://wenwen.soso.com/z/q175197035.htm


Try{...} There are some code that you think may be going wrong, catch is what you think will be a problem, if the problem is exactly what you said in the catch, then he will follow your set, such as will print out, such as the Exit method, etc. ... Then proceed down to the code that executes later.

But if you do not need to try{}, no problem, very good, a problem, the code will stop there, and then give the user a very unfriendly default error prompts, general this hint only developers and other professionals can understand.

That is, add does not add try, the difference is not to add a program does not know how to execute, will stop, and added, you will be given the process of handling abnormal procedures, processing finished, and then go down the code, will not down machine.

In addition, there is a try that can be paired with finally{} without catch,try, but there must be a catch or finally one in the try.

And if you don't want to deal with this method, and in the method of calling together, you can directly in the method of the signature is the method name after the parentheses, add throws Exception, throw the exception to others, like push Taiji, push to others, who call me, who will be responsible for processing.

I don't know if you get it. Other Answers

A try catch is used to catch an exception, and if you don't want to use it, you can have the function throw an exception, which is to add the throws exception name after the function
Still in love with you answer acceptance rate: 15% 2010-01-18 10:09
Try catch, which is used to catch exceptions, does not run smoothly without a try catch, for example, if the capture program with a try catch is missing from the input stream, there are many errors, and when you do not have an exception, execute the statement in the try, and the problem is with the catch Logo out
Questioning person's questioning 2010-01-18 11:03

Ask, Mark out the words, he is how to solve to make the program normal operation. Answer person's supplement 2010-01-18 11:10

catch (Exception e)//The exception to this bracket is the one that shows you the first problem.

Anonymous answer acceptance rate: 23.1% 2010-01-18 10:15

Try catch is an error that is not a code to catch an exception, and can be run. However, some logic errors are not the fault of the code, try catch is used to catch the logic of the code error, as the division of the dividend can not be zero, the code does not error, but it will run the error. That's to catch this kind of anomaly.
One night 暒 峸 answer acceptance rate: 28.2% 2010-01-18 10:37 Try catch is used to catch exceptions. Try to put the code that might appear
Catch inside put exception handling code. If the statement in the try has an exception,
Executes the statement in the catch. Otherwise the statement in the catch does not execute. -vip╰ dans ┎ answer acceptance rate: 31.3% 2010-01-18 11:49
The try below represents the code that may have an exception, and the catch inside this is what happens if the code has an exception change. Of course, if you don't do anything with the catch, the virtual machine does nothing and then continues to run the following code. If you do not use Try...catch, the program will be thrown into the virtual machine when an exception occurs, resulting in the termination of the program. Thank you for adopting

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.