这是我的密码
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中捕获的异常
它会在哪里有效?在这段代码中有必要吗?
https://stackoverflow.com/questions/22498065
复制相似问题