문서의 이전 판입니다!
try ~catch문의 구조
try { // 예외가 발생할 가능성이 있는 문장 코드 } catch (Exception1 e1) { // Exception1이 발생할 경우, 실행될 문장 } catch (Exception1 e2) { // Exception2이 발생할 경우, 실행될 문장 ... } catch (ExceptionX eX){ // ExceptionX가 발생할 경우, 실행될 문장 }
package chapter11; public class ExceptionEx0 { public static void main(String[] args) { System.out.println(1); System.out.println(2); System.out.println(3/0); System.out.println(4); System.out.println(5); System.out.println(6); } }
package chapter11; public class ExceptionEx { public static void main(String[] args) { System.out.println(1); try { System.out.println(2); System.out.println(3/0); System.out.println(4); } catch(ArithmeticException e) { System.out.println(5); } System.out.println(6); } }