UndeclaredThrowableException?? (2) 본문

Troubleshooting

UndeclaredThrowableException?? (2)

miensoap 2024. 6. 2. 23:37

2024.06.02 - [Troubleshooting] - UndeclaredThrowableException ?? (1)

이전글

 

왜 UndeclaredThrowableException 이 발생했을까요?

 

 

 

JavaDoc

 

프록시 인스턴스에서 호출된 메서드 (이 경우 컨트롤러의 메서드) 의 throw 절에 선언된 예외에 할당할 수 없는

'checked exception' 이 발생했을 때 던지는 예외였습니다.

 

package org.apache.tomcat.websocket;

public class AuthenticationException extends Exception

 

tomcat.websocket의 'AuthenticationException` 은 'Exception`을 상속하는 'checked exception` 이었기 때문에  `UndeclaredThrowableException` 이 발생한 것!

 

AOP proxy에서 실행되는 메서드

 

 

@Authenticate
@PostMapping
public IssueListResponse createIssue( ... ) throws AuthenticationException

위와 같이 컨트롤러 메서드 시그니쳐에 해당 예외를 추가해주면 그대로 Advice로 넘어가게 됩니다.

 

또는, RuntimeException (Unchecked Exception) 을 상속하는 custom exception으로 수정했을 때,

정상 작동했습니다.

'Troubleshooting' 카테고리의 다른 글

UndeclaredThrowableException?? (1)  (0) 2024.06.02
[Java] Scanner nextInt() + nextLine()  (0) 2024.01.26