【发布时间】:2019-05-16 13:18:28
【问题描述】:
下面是我试图理解的代码。
public static void main(String[] args)
{
try
{
System.out.println(args[0]);
}
catch (ArrayIndexOutOfBoundsException e)
{
System.out.println("ArrayIndexOutOfBoundsException");
throw new NullPointerException();
}
catch (NullPointerException e)
{
System.out.println("NullPointerException");
throw new Exception();
}
catch (Exception e)
{
System.out.println("Exception");
}
}
一切都很好,除非我抛出 new Exception();。因此,当我这样做时,会出现一个错误,即“未处理的异常类型异常”,尽管我在下面提供了 catch 语句来处理它。
所以我知道问题的解决方案,但我想知道原因。我缺少什么见解。
谁能解释一下。
【问题讨论】:
-
try 块没有抛出异常。