프로그램이 예상치 못한 상황을 만났을 때 오류를 발생시키는 것 (throw new Exception())
try{
doSomething();
}catch (Exception e){
lof.error("Exception is occurred", e);
handleException(e);
//throw e;
}
@ResponseStatus(HttpStatus.FORBIDDEN)
@ExceptionHandler(IllegalAccessException.class)
public String handleIllegalAccessException(
IllegalAccessException e){
log.error("IllegalAccessException is occurred.", e);
return "INVALID_ACCESS";
}
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler{
@ResponseStatus(value = HttpStatus.FORBIDDEN)
@ExceptionHandler(IllegalAccessException.class)
public ErrorResponse handleIllegalAccessException(IllegalAccessException e){
log error("Illegal Exception : ", e);
return new ErrorResponse("ACCESS_DENIED", "Illegal Exeption ocuurred,");
}
}