编写应用程序,从命令行传入两个整型数作为除数和被除数。要求程序中捕获NumberFormatException 异常和ArithmeticException 异常,而且无论在哪种情况下,“总是被执行”

public static void main(String[] args) {
				try {
					int a=Integer.parseInt(args[0]);
					int b=Integer.parseInt(args[1]);
					System.out.println(a+b);
				}catch (NumberFormatException e) {
					System.out.println("数字格式异常");
				}catch (ArithmeticException e1) {
					System.out.println("算数异常");
				}catch (Exception e2) {
					System.out.println("发现异常");
				}finally {
					System.out.println("总是被执行");
				}
			}

猜你喜欢

转载自blog.csdn.net/qq_43189642/article/details/84993444