Java 常見異常lllegalArgumentException
lllegalArgumentException
java.lang.lllegalArgumentException是非法參數(shù)異常,迪常是調(diào)用方法時(shí)引發(fā)的異常。當(dāng)給一個(gè) 方法傳遞的參數(shù)與實(shí)際定義不相符時(shí),會(huì)拋出lllegalArgumentException異常。
import java.io.File;
//NumberFormatException
public class Demo {
public static String createFilePath(String parent, String filename) throws IllegalArgumentException{
if (parent == null)
throw new IllegalArgumentException("文件路徑不能為空! ");
if(filename == null)
throw new IllegalArgumentException("文件名稱不能為空! ");
return parent + File.separator + filename;
}
public static void main(String[] args) {
System.out.println(Demo.createFilePath("dir1" ,"file1"));
System.out.println();
System.out.println(Demo.createFilePath(null, "file1"));
}
}
點(diǎn)擊加載更多評(píng)論>>