public class ExceptionTest { public static void main(String[] args) { int x = 10, y0 = 0, y1 = 2, z = 10; System.out.println("main: z= " +z); try{ System.out.println("try: before 'divide by 0' "); //주석전 : catch(ArithmeticException): java.lang.ArithmeticException: / by zero //주석후 : try: afer 'divide by 0' //z = x/y0; z = x/y1; System.out.println("try: afer 'divide by 0' "); } catch(ArithmeticException e) { System.out.println("catch(ArithmeticException): " +e); } catch(Exception e) { System.out.println("catch(Exception): "+e); } finally{ System.out.println("finally: z =" +z); } System.out.println("main: z=" +z); } }
반응형
'프로그래밍' 카테고리의 다른 글
error C2440: '=' : 'LPSTR'에서 'LPCWSTR'(으)로 변환 (0) | 2013.11.14 |
---|---|
수식의 괄호의 쌍을 검사하는 프로그램 (0) | 2013.11.13 |
추상 클래스 (0) | 2013.11.13 |
순차 자료구조를 이용하여 구현한 스택 프로그램 (0) | 2013.11.12 |
연결 리스트를 이용한 다항식의 덧셈 프로그램 (0) | 2013.11.12 |