package com.basic;//사용자 정의 예외 class UserException extends Exception{ public UserException(String str){ super(str); } } public class ExcepTest09 { public static void main(String[] args) { try{ int a= -11; if(a<=0){ //사용자가 정의한 예외를 인위적으로 발생시킴 throw new UserException("양수가 아닙니다."); } } catch(UserException e){ System.out.println(e.getMessage()); } } }
양수가 아닙니다.
'Java > Exception Handing' 카테고리의 다른 글
예비 (0) | 2012.04.11 |
---|---|
예외처리 throw사용법 (0) | 2012.04.11 |
예외처리 throws 사용법 (0) | 2012.04.11 |
예외처리 다중 catch문 사용하기 (0) | 2012.04.11 |
예외처리 finally 사용법 (0) | 2012.04.11 |