这是我的代码
static void tryit() throws Exception
{
System.out.println(10 / 0);
}
public static void main(String[] args)
{
try {
tryit();
} catch (Exception e) {
System.out.println("Exception caught in main");
}
}
在这里徘徊的是,在此代码的第 1 行中throws Exception
究竟做了什么?
即使我没有使用它,我也得到了相同的输出
输出:main 中捕获的异常
哪里会有效果?这段代码有必要吗?