package ch11.Exception;
import java.util.InputMismatchException;
import java.util.Scanner;
public class Ex02 {
public static void main(String[] args) {
// Exception : 예외발생 ~ 처리
// A, B, C
Scanner sc=new Scanner(System.in);
try {
System.out.print("x : ");
int x=sc.nextInt();
System.out.print("y : ");
int y=sc.nextInt();
int z=x/y;
System.out.println("z : " + z);
}catch(ArithmeticException e) {
System.out.println("0으로 나눌 수 없습니다.");
}catch(InputMismatchException e) {
System.out.println("정수만 입력하세요.");
}finally {
System.out.println("finally");
}
sc.close();
}
}
x : 10
y : 0
0으로 나눌 수 없습니다.
finally
x : ㅁㅁㅁ
정수만 입력하세요.
finally