//package exception;
//抛异常:throw 和throws
public class TestTrow {
public static void main(String[]args){
//throw
// String s="abcd";
// if (s.equals("abcd")){
// throw new NumberFormatException();
// }else{
// System.out.println(s);
// }
//throws
try{
function();
}catch (NumberFormatException ne){
System.out.println("非数据类型,不能强制转换");
ne.printStackTrace();
}
}
public static void function() throws NumberFormatException {
String s="abcd";
System.out.println(Double.parseDouble(s));
}
}
抛异常:throw 和throws
最新推荐文章于 2023-05-03 21:45:17 发布