Java Try Catch finally problem

Source: Internet
Author: User
Tags try catch

The problem with writing a program today is that you need to return the data when the while loop throws an exception.

It is correct to find that the try block is placed outside the while loop.

private static void Test5 () {int count=1;      while (count<100) {count++;   try {} catch (Exception e) {}finally{System.out.println ("final:" +count); }     } }

Results

final:53
final:54
Final:55
final:56
final:57
final:58
final:59
Final:60
final:61
final:62
final:63
Final:64
Final:65
final:66
final:67
final:68
final:69
Final:70
final:71
final:72
final:73
final:74
Final:75
final:76
Final:77
final:78
final:79
Final:80
final:81
final:82
final:83
final:84
Final:85
Final:86
final:87
final:88
final:89
Final:90
final:91
final:92
final:93
final:94
Final:95
final:96
final:97
Final:98
final:99
final:100

Java Try Catch finally problem

Related Article

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.