면) 두 가지 이유로 실패할 수 있는 함수의 결과를 어떻게 표현해야 하느냐는 문제를 해결해
야 한다. 그것이 바로
register
가
ExcludedException
과
DuplicateException
이라는 두
체크 예외를
throws
절에 선언해둔 이유이다. 코드로 설명하면, 우리는
Result
<
Customer
,
Either
<
ExcludedException
,
DuplicateException
>>
와 비슷한 무언가를 원한다.
일반적인
Either
타입을 사용할 수도 있겠지만, 전략으로 채택하기에는 조금 너무 멀리 나간
감이 있다. 예외를 선언하는 순서가 중요하지 않은 자바와 달리
Either
<
ExcludedException
,
DuplicateException
>
는
Either
<
DuplicateException
,
ExcludedException
>
과 같지
않다.
Either
는 기껏해야 혼동이나 야기하고 예외가 셋 이상인 경우에는 문제를 더 악화시키
기까지 한다.
OneOf
<
ExcludedException
,
DuplicateException ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.