75.Java異常處理機制-手動拋出異常

 1 package testDate;
 2 import java.io.File;
 3 import java.io.FileNotFoundException;
 4 public class TestReadFile {
 5     public static void main(String[] args) {
 6         File f=new File("d:/b.txt");
 7         if(!f.exists()){
 8             try{
 9                 //手動拋出異常
10                 throw new FileNotFoundException("File can't be found !");
11             }catch(FileNotFoundException e){
12                 e.printStackTrace();
13             }
14         }
15     }
16 }

相關文章
相關標籤/搜索