We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Originally posted by JoisFe March 26, 2023
/** * IndexOutOfBoundsException을 생성한다. * * @param lowerBound 인덱스의 최솟값 * @param upperBound 인덱스의 최댓값 + 1 * @param index 인덱스의 실젯값 */ public IndexOutOfBoundsException(int lowerBound, int upperBound, int index) { // 실패를 포착하는 상세 메시지를 생성한다. super(String.format("최솟값: %d, 최댓값: %d, 인덱스: %d", lowerBound, upperBound, index)); // 프로그램에서 이용할 수 있도록 실패 정보를 저장해둠. this.lowerBound = lowerBound; this.upperBound = upperBound; this.index = index; }
toString이 반환한 값에 포함된 정보를 얻어올 수 있는 API를 제공하자
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Discussed in https://github.com/orgs/Study-2-Effective-Java/discussions/179
Originally posted by JoisFe March 26, 2023
아이템 75. 예외의 상세 메시지에 실패 관련 정보를 담으라
스택 추적 (Stack Trace)
예외의 toString 메서드에 실패 원인에 관한 정보를 가능한 많이 담아 반환하는 일은 매우 중요
예외의 상세 메시지를 작성하는 방법
실패 순간을 포착하려면 발생한 예외에 관련된 모든 매개변수와 필드의 값을 실패 메시지에 담아야 함
예외의 상세 메시지와 최종 사용자에게 보여줄 오류 메시지를 혼동해선 안됨
실패를 적절히 포착하려면 필요한 정보를 예외 생성자에서 모두 받아서 상세 메시지까지 미리 생성해놓는 방법 또한 괜찮음
예외는 실패와 관련한 정보를 얻을 수 있는 접근자 메서드를 적절히 제공하는 것이 좋음
toString이 반환한 값에 포함된 정보를 얻어올 수 있는 API를 제공하자
일반 원칙을 따른다는 관점에서는 비검사 예외에도 상세 정보를 알려주는 접근자 메서드를 제공하는 것을 권함!The text was updated successfully, but these errors were encountered: