手动抛出自定义异常!

来源:互联网 发布:.cc域名权重 编辑:程序博客网 时间:2024/05/07 16:35
class FuShuException extends Exception{FuShuException(String m){super(m);}}class Demo{int div(int a,int b)throws FuShuException{if(b<0)throw new FuShuException("大爷的,你会不会啊!!!");return a/b;}}class Demodemo8{public static void main(String[] args){Demo d=new Demo();try{int x=d.div(4,-2);System.out.println(x);}catch (FuShuException e){System.out.println(e);//e.printStackTrace();//System.out.println("hahahahha");}}}//手动进行自定义异常的抛出!  父类已经定义子类异常直接继承,并用super语句标示就OK!