package com.study.javastudy.study;
public class ExceptionExam2 {
public static void main(String[] args) {
int i = 10;
int j = 0;
try {
int k = divide(i, j);
System.out.println(k);
} catch (ArithmeticException e) {
System.out.println(e.toString()); // java.lang.ArithmeticException: / by zero
}
}
public static int divide(int i, int j) throws ArithmeticException{
// throws는 ArithmeticException 예외가 발생하니 그쪽에다 처리하도록 명령한다
int k = i/j;
return k;
}
}
'자바 기초' 카테고리의 다른 글
사용자 정의 Exception (0) | 2024.01.29 |
---|---|
Exception 발생시키기 (0) | 2024.01.29 |
Exception (0) | 2024.01.29 |
익명 클래스 (0) | 2024.01.29 |
내부 클래스(지역 중첩 클래스, 지역 클래스) (0) | 2024.01.29 |