Java 常见异常lllegalArgumentException
lllegalArgumentException
java.lang.lllegalArgumentException是非法参数异常,迪常是调用方法时引发的异常。当给一个 方法传递的参数与实际定义不相符时,会拋出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"));
}
}
点击加载更多评论>>