异常

来源:互联网 发布:win10梦幻桌面软件 编辑:程序博客网 时间:2024/05/16 05:48
源程序:
public class Test{
public static void main(String[] args){
System.out.println("********** 计算开始 **********") ;
int i = 0 ;
int j = 0 ;
try{
String str1 = args[0] ;
String str2 = args[1] ;
i = Integer.parseInt(str1) ;
j = Integer.parseInt(str2) ;
int temp = i / j ;
System.out.println("两个数字相除结果:" + temp) ;
}catch(ArithmeticException e){
System.out.println("算术异常:" + e) ;
}catch(ArrayIndexOutOfBoundsException e){
System.out.println("数组越界异常:" + e) ;
}catch(NumberFormatException e){
System.out.println("数字转换异常:" + e) ;
}
System.out.println("********** 计算结束 **********") ;
}
}
0 0