package com.exception;
public class Main {
public static void main(String args[]){
try{
if(args.length!=2){
throw new ParameterNumberException();
}else{
if(!check(args[0])||!check(args[1])){
throw new ParameterFormatException();
}
}
}catch(ParameterNumberException e){
System.out.println(e);
e.printStackTrace();
}catch(ParameterFormatException e){
System.out.println(e);
e.printStackTrace();
}
}
//检测输入的字符串是否都是整数
public static boolean check(String s){
for(int i=0;i
return false;
}
}
return true;
}
}
class ParameterNumberException extends Exception{
ParameterNumberException(){
super("参数个数异常!");
}
public String toString(){
return "ParameterNumberException";
}
}
class ParameterFormatException extends Exception{
ParameterFormatException(){
super("参数格式异常!");
}
public String toString(){
return "ParameterFomatException";
}
}