Throws 활용하기
package ch10;
public class Throws {
public static void main(String[] args) {
for(int i=0; i<10; i++) {
int num = (int)(Math.random()*10);//*한 만큼의 개수를 출력한다. 따라서 10개를 출력한다!
try {
cal(num);
} catch(Exception e) {
System.out.println("0으로 못 나눠!");
}
}
}
private static void cal(int num) throws Exception {
// System.out.printf("%d / %d = %d\n", 100,num,100/num);
// 출력이 아니라 예외를 강제로 발생시키는 경우!
try {
throw new Exception();
} catch (Exception e) {
System.out.println("여기서 에러 발생");
}
}
}