1异常(throw、throws关键字、try...catch、Throwable类)

1异常(throw、throws关键字、try...catch、Throwable类)

1异常(throw、throws关键字、try...catch、Throwable类)
1异常(throw、throws关键字、try...catch、Throwable类)

声明异常throws

1异常(throw、throws关键字、try...catch、Throwable类)
1异常(throw、throws关键字、try...catch、Throwable类)

捕获异常try…catch

1异常(throw、throws关键字、try...catch、Throwable类)

package Text1;
import java.io.IOException;
public class Demo12 {
    public static void main(String[] args) {
        try {
            readFile("d:\\a.tx");
        } catch (IOException e) {
            System.out.println("传递文件的后缀不是txt");
        }
        System.out.println("后续代码");
    }
    public static void readFile(String fileName) throws IOException {
        if(!fileName.endsWith(".txt")){
            throw new IOException("文件后缀名不对");
        }
        System.out.println("路径没问题,读取文件");
    }
}

1异常(throw、throws关键字、try...catch、Throwable类)

Throwable类中3个异常处理方法

1异常(throw、throws关键字、try...catch、Throwable类)

上一篇:MultiDex解析


下一篇:UDP编程