refactor: FillinStackTrace Overring을 통한 Exception 비용 절감 #141
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🔥이슈
🔎 작업 내용
문제 상황
JVM은 예외가 발생하면 다음과 같이 작동해요.
이처럼 StackTrace를 통해 상위 계층으로 전파시키며 정보들을 수집하는 과정을 가진다. 이때 순회 비용이 무시할 수 없을 정도로 크게 작용한다.
해결 방안
단순히 순회를 하는
FillInStackTrace()를 오버라이딩한다. 예외를 전파시키지 않고 바로 자신을 return 시키므로서 비용을 절감할 수 있다.NPE, OOP처럼 Java의 기본 예외와 달리 Custom Exception은 목적은 예외 추적이 아닌 하위 비즈니스 로직의 수행을 막는 것이다. 따라서 StackTreace를 사용하지 않도록하는 것이 크게 문제되지 않다고 판단했다.
적용 결과, 여러 Exeption이 출력되지 않고, 정확히 CustomException만 출력되는 것을 확인할 수 있다.

🔧 관련 링크
Java 예외 생성 비용은 비싸다