public class BelowZeroException extends Exception
{
static final long serialVersionUID = -3387516948L;
public BelowZeroException(){}
public BelowZeroException(String message)
{
super(message);
}
}
public class BelowZeroException extends Exception
{
static final long serialVersionUID = -3387516948L;
public BelowZeroException(){}
public BelowZeroException(String message)
{
super(message);
}
}
public class DivisionDemo
{
public static void main(String[] args)
{
try
{
int m = Integer.parseInt(args[0]);
int n = Integer.parseInt(args[1]);
int result = divide(m,n);
}
catch(BelowZeroException e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}
catch(NumberFormatException e)
{
System.out.println("数据类型不一致");
e.printStackTrace();
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("缺少命令行参数");
}
catch(ArithmeticException e)
{
System.out.println("除0了");
}
}
public static int divide(int m,int n) throws BelowZeroException
{
if(m < 0 || n < 0)
{
throw new BelowZeroException("输入负数了");
}
return m / n;
}
}
public class DivisionDemo
{
public static void main(String[] args)
{
try
{
int m = Integer.parseInt(args[0]);
int n = Integer.parseInt(args[1]);
int result = divide(m,n);
}
catch(BelowZeroException e)
{
System.out.println(e.getMessage());
e.printStackTrace();
}
catch(NumberFormatException e)
{
System.out.println("数据类型不一致");
e.printStackTrace();
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("缺少命令行参数");
}
catch(ArithmeticException e)
{
System.out.println("除0了");
}
}
public static int divide(int m,int n) throws BelowZeroException
{
if(m < 0 || n < 0)
{
throw new BelowZeroException("输入负数了");
}
return m / n;
}
}