请问该程序的运行结果是什么?
class Example {
public static void main(String[] args){
for(int i=0; i<10; ++i){
try{
try{
if(i%3 == 0) throw new Exception("E0");
System.out.println(i);
}
catch(Exception inner){
i * = 2;
if(i%3 == 0) throw new Exception("E1");
}
finally{
++i;
}
}
catch(Exception outer){
i += 3;
}
finally{
--i;
}
}
}
}
class Example {
public static void main(String[] args){
for(int i=0; i<10; ++i){
try{
try{
if(i%3 == 0) throw new Exception("E0");
System.out.println(i);
}
catch(Exception inner){
i * = 2;
if(i%3 == 0) throw new Exception("E1");
}
finally{
++i;
}
}
catch(Exception outer){
i += 3;
}
finally{
--i;
}
}
}
}
执行
catch-inner和finally
catch-outer和fianlly
i=3
执行for循环++i,i=4
执行
System.out.println(i);
两个finally
i=4
执行for循环++i,i=5
执行
System.out.println(i);
两个finally
i=5
执行for循环++i,i=6
执行
两个catch和finally(先catch后finally)
i=15
执行for循环 判断 退出
public static void main(String[] args)
{
for(int i=0; i<10; ++i)
{
try
{
try
{
if(i%3 == 0) throw new Exception("E0");
System.out.println(i);
System.out.println("-------------");
}
catch(Exception inner)
{
//i * = 2;//这一行应该注释掉
if(i%3 == 0) throw new Exception("E1");
}
finally
{
++i;
}
}
catch(Exception outer)
{
i += 3;
}
finally
{
--i;
}
}
}
}
输出结果 4,5,应该先执行内部的异常,再执行外面的异常