java空指针异常如何抛出
1、public static void main(String[] args){
try{
getNullException();
}catch (NullPointerException e){
System.out.println("捕捉到的异常:" + e.getMessage());
}
}
public static void getNullException(){
String s = null;
try{
s = s.replace("a","");
}catch (Exception e){
throw new NullPointerException();
}
}
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:91
阅读量:93
阅读量:38
阅读量:192
阅读量:35