public class yicang extends Exception{
yicang(String ms){
super(ms);
}
static void Throw() throws yicang {
int a=0,b=3;
if(a!=0) {
System.out.println(b/a);
}
else{
throw new yicang("除数不能为0");
}
}
public static void main(String []args) {
try
{Throw();}
catch(yicang e) {
e.printStackTrace();
}
}
仿照例7.9,自定义一个异常类,并在某场景下抛出该异常对象。
最新推荐文章于 2021-10-21 09:31:07 发布