自定义异常的使用
package ImoocException;
public class my_Exception extends Exception {
/**
*
*/
private static final long serialVersionUID = 1L;
public my_Exception() {
System.out.println("使用了这个自定义的类1!");
}
public my_Exception(String str) {
super(str);
System.out.println("使用了这个自定义的类2!");
}
public void devide(int a,int b) throws Exception {
if(b==0) {
throw new my_Exception("被除数不能为0");
}
else {
System.out.println("it is ok!");
}
}
public static void main(String[] args)throws Exception {
// TODO Auto-generated method stub
ImoocException imooc=new ImoocException ();
try {
imooc.devide(10, 0);
}
catch(my_Exception e) {
System.out.println("异常抛出!");
}
}
}
最后结果还是出来
Exception in thread "main" java.lang.Exception
at ImoocException.ImoocException.devide(ImoocException.java:6)
at ImoocException.my_Exception.main(my_Exception.java:29)
这是怎么回事?