创建异常的对象(了解了解了解即可)
public class Demo03Exception {
public static void main(String[] args) {
String s="a.txt";//修改txt为t1xt就能正常运行 不修改以txt结尾就会进if抛出异常
method(s);
}
public static void method(String s){
if(s.endsWith(".txt")){
throw new NullPointerException();
}
System.out.println("我要执行了");
}
}

浙公网安备 33010602011771号