Java异常处理中的一个问题

package com.doudou_01;

import java.io.FileWriter;
import java.io.IOException;

public class Demo {
    public static void main(String[] args) {
        
        
        try {
            FileWriter fl = new FileWriter("a.txt");
            fl.write("huang");
            fl.write("love");
            fl.write("liao");
            fl.close();
            System.out.println("nice!");
        } catch(Exception e) {
            System.out.println(e.getMessage());
        }
        
//        try {
//            method(100);
//            System.out.println("nice!");
//        } catch (MyException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }
    }
    
    
//    public static void method(int grade) throws MyException {
//        if(grade < 0 || grade > 0) {
//            throw new MyException("ss");
//        }
//        
//        System.out.println("成绩非常规范哦");
//    }
}

在上面的代中,IO异常处理被捕获之后本应该停止“FileWriter fl = new FileWriter("a.txt");”try中之后的程序,但是try中后面的程序依然再执行,这是为什么呢?

待解决!

猜你喜欢

转载自www.cnblogs.com/doubest/p/10462066.html