- import java.io.IOException;
- 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");
- }
- }
复制代码 代码的运行结果为:caught IOException noException
代码中try块中new ExceptionTest()调用methodA()方法,
而方法本身抛出异常,它们之间的关系搞得有些混乱了
谁可以帮我理顺说明下么? |