package test4;
/**
* 〈一句话功能简述〉<br>
* 〈〉
*
* @author abu
* @create 2019/7/19
* @since 1.0.0
*/
public class EcmDef {
public static void main(String[] args){
try{
int i = Integer.parseInt(args[0]);
int j = Integer.parseInt(args[1]);
ecm(i,j);
}catch (NumberFormatException e){
System.out.println("数据类型错了哦");
}catch (ArrayIndexOutOfBoundsException e){
System.out.println("命令行参数好像不够哟");
}catch (ArithmeticException e){
System.out.println("分母不能为零哦");
}catch (EcDef e){
System.out.println(e.getMessage());
}
}
public static void ecm(int i, int j) throws EcDef{
if(i < 0 || j < 0){
throw new EcDef("不能输入负数哦");
}
System.out.println(i/j);
}
}
class EcDef extends Exception{
static final long serialVersionUID = -23849482918394L;
public EcDef(){
}
public EcDef(String msg){
super(msg);
}
}
练习15——抛出异常的练习
最新推荐文章于 2022-04-25 14:28:34 发布