欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

throw Exception 抛异异常

程序员文章站 2022-07-15 12:55:06
...



if(this.aop == null)throw new NullPointerException("aop is null");
if(method == null)throw new NullPointerException("method is null");

if(something==null)
      throw new NullPointerException(); 
    else
        return "something";


public Object sell(){
if(checkUser())
Object obj = new Object();

return obj ;
}else{
throw new RuntimeException();
}
}

if (t == null) {throw new NullPointerException("something bad");}
if (o == null) throw new NullPointerException();


算术异常类:ArithmeticExecption
空指针异常类:NullPointerException
类型强制转换异常:ClassCastException
数组负下标异常:NegativeArrayException
数组下标越界异常:ArrayIndexOutOfBoundsException
违背安全原则异常:SecturityException
文件已结束异常:EOFException
文件未找到异常:FileNotFoundException
字符串转换为数字异常:NumberFormatException
操作数据库异常:SQLException
输入输出异常:IOException
方法未找到异常:NoSuchMethodException