Beny's Study
[강의] 로그인 예외처리 본문
package com.kh.ex02.user_exception;
public class UseException {
public static void main(String[] args) {
String userID = "test";
String userPW = "1234";
String inputID = "test";
String inputPW = "1234";
try {
if(userID.equals(inputID) == false) {
throw new LoginException("아이디가 맞지 않습니다!");//괄호안의 ""가 cause
}
if(userPW.equals(inputPW) == false) {
throw new LoginException("비밀번호가 맞지 않습니다!");
}
System.out.println("로그인 성공");
} catch (LoginException e) {
System.out.println("로그인 예외처리!");
e.printStackTrace();
} finally {//무조건 출력
// 주로 자원을 정리해주는 곳
inputID = null;
inputPW = null;
System.out.println("자원이 정리되었습니다.");//79@
}
}
}
[출력]
로그인 성공
자원이 정리되었습니다.
'[JAVA] > 11.예외처리' 카테고리의 다른 글
[강의] throw 와 throws (0) | 2022.05.29 |
---|---|
[강의] 예외클래스 종류 (0) | 2022.05.29 |
file 사용이력보기 메소드(수정날짜보기) (0) | 2022.04.20 |
file 이름바꾸는 메소드 _ .renameTo( ) (0) | 2022.04.20 |
file 권한설정메소드 _ .setWritable( ) (0) | 2022.04.20 |