gpt4 book ai didi

java - Java 代码中的 "misplaced construct(s)"靠近 catch

转载 作者:行者123 更新时间:2023-12-01 06:27:52 28 4
gpt4 key购买 nike

我无法用 Java 编译以下代码,错误是:构造错误。怎么了?

public class ExceptionsTutorial {

public static void main(String[] argv) throws Exception{

try{
System.out.println("A");

try{
System.out.println("B");
throw new Exception("1");
}
catch{
System.out.println("C");
throw new Exception("2");
}
finally{
System.out.println("D");
throw new Exception("3");
}

}
finally{
System.out.println("F");
}

}
}

最佳答案

catch 必须声明它捕获的异常:

catch (Exception E) {
System.out.println("C");
throw new Exception("2");
}

关于java - Java 代码中的 "misplaced construct(s)"靠近 catch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1690353/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com