62,614
社区成员
发帖
与我相关
我的任务
分享
public class FinallyTest
{
public static void main(String[] args)
{
//System.out.println("main--- " + new FinallyTest().print());
}
public int print()
{
int i = -1;
try
{
Thread.sleep(1);
i = 1 / 0;
return i;
}
catch (IndexOutOfBoundsException e)
{
}
finally
{
System.out.println("finally--- " + i);
return i;
}
}
}
public void print()
{
int i = -1;
try
{
Thread.sleep(1);
i = 1 / 0;
}
catch (IndexOutOfBoundsException e)
{
}
finally
{
System.out.println("finally--- " + i);
}
}
public void print() throws Exception {
int i = -1;
try {
Thread.sleep(1);
i = 1 / 0;
} catch (Exception e) {
System.out.println("catch step1.");
throw e;
} finally {
System.out.println("finally--- " + i);
return;
}
}
public class FinallyTest
{
public static void main(String[] args)
{
//System.out.println("main--- " + new FinallyTest().print());
}
public void print()
{
int i = -1;
try
{
Thread.sleep(1);
i = 1 / 0;
}
catch (IndexOutOfBoundsException e)
{
}
finally
{
System.out.println("finally--- " + i);
return;//这里加个return
}
}
}
public void print()
{
int i = -1;
try
{
Thread.sleep(1);
//i = 1 / 0;
//return i;
}
catch (IndexOutOfBoundsException e)
{
}
finally
{
System.out.println("finally--- " + i);
//return i;
}
}