@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

+ Recent posts