第一种:
class Demo
{
public static void fun()
{
try
{
throw new Exception();
System.out.println("A");
}
catch (Exception e)
{
System.out.println("B");
}
}
public static void main(String[] args)
{
try
{
func();
}
catch (Exception e)
{
System.out.println("C");
}
System.out.println("D");
}
}
第二种:
class Demo
{
public static void showExce()throws Exception
{
throw new Exception();
}
public static void main(String[] args)
{
try
{
showExce();
System.out.println("A");
}
catch (Exception e)
{
System.out.println("B");
}
finally
{
System.out.println("C");
}
System.out.println("D");
}
}
为什么第一种编译失败,第二种能够通过,打印A的语句不是两种情况下都执行不到吗?
|
|