public class ExceptionTest { public static void main(String args[]) {
try {
new ExceptionTest().methodA(5);
} catch (IOException e) {
System.out.println("caught IOException");
} catch (Exception e) {
System.out.println("caught Exception");
} finally {
System.out.println("no Exception");
}
} void methodA(int i) throws IOException {
if (i%2 != 0)
throw new IOException("methodA IOException");
}
}
为什么在try语句中可以这样写,new ExceptionTest(),主方法是个静态的方法?
try {
new ExceptionTest().methodA(5);
} catch (IOException e) {
System.out.println("caught IOException");
} catch (Exception e) {
System.out.println("caught Exception");
} finally {
System.out.println("no Exception");
}
} void methodA(int i) throws IOException {
if (i%2 != 0)
throw new IOException("methodA IOException");
}
}
为什么在try语句中可以这样写,new ExceptionTest(),主方法是个静态的方法?
private String name;
}