Try Catch Finally__volatile

Source: Internet
Author: User
Tags finally block try catch

1 The results of the following program output are correct ()
public class Test1 {
public static String output = "";
public static void foo (int i)
{
try{
if (i = = 1)
{
throw new Exception ();
}
}catch (Exception e) {
output+= "2";
Return
}finally {
output+= "3";
}
output+= "4";
}
public static void Main (string[] args) {
Foo (0);
Foo (1);
SYSTEM.OUT.PRINTLN (output);
}
}
A Error
B 342
C 34234
D 3423
Note: for try Catch finally
Finally will certainly execute, secondly, if there is an exception, and the exception statement block is not return, the try~finally statement block of the outer statement will also execute, and is try~finally execution completed after execution, in short, the peripheral statement block to some extent, will be carried out. A finally block of statements must be executed before the try and catch statements execute return.

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.