프레임워크/Spring, Spring Boot

[메타코딩] 스프링부트 강좌 31강(블로그 프로젝트) - Exception처리하기

고용인 2022. 8. 5. 15:05
@ControllerAdvice
@RestController
public class GlobalExceptionHandler {

	@ExceptionHandler(value=Exception.class)
	public String handleArgumentException(IllegalArgumentException e) {
		return "<h1>"+e.getMessage()+"</h1>";
	}
}

@ControllerAdvice : 모든 Exception에 대해 수렴되게 하는 어노테이션입니다.

@ExceptionHandler(value=Exception.class) : Exception의 종류를 선언하여, 해당 Exception에 대해서 받을 수 있습니다.

 

 

 

강의 주소 : https://youtu.be/qYxWWWVpJkA