[SELF Mini Project -3] 사용자 정의 예외처리

현이·2023년 12월 12일
0

Self Study

목록 보기
3/5
  • Exception 패키지 생성
    ->
  • enum ExceptionCode 생성
package com.selfstudy.frame.exception;

import lombok.Getter;

@Getter
public enum ExceptionCode {
    MEMBER_NOT_FOUND(404, "Member not found"),

    MEMBER_EXISTS(409, "Member exists");

    private final int status;
    private final String message;

    ExceptionCode(int statusCode, String message) {
        this.status = statusCode;
        this.message = message;
    }

}
  • class BusinessLogicException 생성 (RuntimeException 상속)
package com.selfstudy.frame.exception;

import lombok.Getter;

@Getter
public class BusinessLogicException extends RuntimeException {
    private final ExceptionCode exceptionCode;

    public BusinessLogicException(ExceptionCode exceptionCode) {
        super(exceptionCode.getMessage());
        this.exceptionCode = exceptionCode;
    }
}

0개의 댓글