RejectedExecutionException
- 실행을 위해 작업을 수락할 수 없는 경우 Executor에서 발생하는 예외입니다.
- ex. 수정, 삭제를 할 때 catch문으로 넘어가는 경우
@PutMapping("/comments/{id}")
public ResponseEntity<ApiResponseDto> updateComment(@AuthenticationPrincipal UserDetailsImpl userDetails, @PathVariable Long id, @RequestBody CommentRequestDto requestDto) {
try {
CommentResponseDto result = commentService.updateComment(id, requestDto, userDetails.getUser());
return ResponseEntity.ok().body(result);
} catch (RejectedExecutionException e) {
return ResponseEntity.badRequest().body(new ApiResponseDto("작성자만 수정 할 수 있습니다.", HttpStatus.BAD_REQUEST.value()));
}
}
IllegalArgumentException
- 런타임 에러
- 오류 발생 지점에서 잘못 된 파라미터가 넘어갔을 때 발생하는 오류
- ex. DB에서 데이터를 가져와(find) 중복체크
#1
if (userRepository.findByUsername(username).isPresent()) {
throw new IllegalArgumentException("이미 존재하는 회원입니다.");
}
#2
User user = userRepository.findByUsername(username).orElseThrow(
() -> new IllegalArgumentException("등록된 사용자가 없습니다.")
);