I could not compile the following code in Java, error is: misplaced construct(s). What's wrong?
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");
}
开发者_StackOverflow catch{
System.out.println("C");
throw new Exception("2");
}
finally{
System.out.println("D");
throw new Exception("3");
}
}
finally{
System.out.println("F");
}
}
}
catch
must declare what exception it catches:
catch (Exception E) {
System.out.println("C");
throw new Exception("2");
}
Read up on Java catch blocks. There is a required element that is missing in your code.
Note that Java's behavior is slightly different from that of C# or Python in this regard.
精彩评论