10 http cafe naver comthisjava 117 Number Format
10장. 예외처리 이것이 자바다(http: //cafe. naver. com/thisjava) 1/17
Number. Format. Exception v Integer. parse. Int(String s) - 정수로 변환 v Integer. parse. Double(String s) – 실수로 변환 v 숫자로 변환될 수 없는 문자가 포함되어 있으면 Number. Format. Exception 발생 String data 1=“ 100”; String data 2 = “a 200”; Sytem. out. println(Integer. parse. Int(data 1) + Integer. parse. Int(data 2)); 9/17
(2)상위 메소드로 전달 // throwable class 15/17
사용자 정의 예외 예제 class Divide. By. Zero. Exception extends Arithmetic. Exception { public Divide. By. Zero. Exception() { super("0으로 나눌 수는 없음"); //수퍼 클래스의 생성자 호출하여 에러 메시지 저장 } } public class Exception. Test { public static void main(String[] args) { doubleresult; try { result = quotient(1, 0); } catch (Divide. By. Zero. Exception e) { System. out. println(e. get. Message()); } } public static double quotient(int n, int d) throws Divide. By. Zero. Exception { if (d == 0) throw new Divide. By. Zero. Exception(); return (double) n/d; } } 20/17
이것이 자바다(http: //cafe. naver. com/thisjava) 24/17
- Slides: 24