-
Notifications
You must be signed in to change notification settings - Fork 22
Item74. 메서드가 던지는 모든 예외를 문서화하라 #120
New issue
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
Open
Limwin94
wants to merge
4
commits into
main
Choose a base branch
from
item74
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # item74. 메서드가 던지는 모든 예외를 문서화하라 | ||
|
|
||
| 이번 아이템에서는 각 메서드가 던지는 예외를 문서화하는데 충분한 시간을 쏟아야 한다고 설명하고 있습니다. | ||
|
|
||
| item56을 참고하면 Swift의 경우 `Parameters & Retrun Values` 항목에서 주석 중`Throws`를 작성해 발생할 수 있는 에러에 대해 문서화를 할 수 있도록 기본 제공하고 있습니다. | ||
|
|
||
| ```swift | ||
| /** | ||
| 과일을 받아 해당 과일로 쥬스를 만듭니다. | ||
|
|
||
| - Parameter fruit: 쥬스로 만들 과일 | ||
|
|
||
| - Throws: 쥬스를 만들 수 없는 과일이 들어올 경우 'BlendedError.unusableFruit' | ||
| */ | ||
| func makeJuice(using fruit: Fruit) throws -> Juice { | ||
| // 만들 수 없는 재료일 경우 | ||
| if fruit.name == "Durian" { | ||
| throw BlendedError.unusableFruit | ||
| } | ||
|
|
||
| // make juice code | ||
|
|
||
| return Juice(fruit: fruit) | ||
| } | ||
| ``` | ||
|
|
||
| <br> | ||
|
|
||
| 이렇게 주석으로 문서화를 진행해놓을 경우, `makJuice()`를 호출하는 사용자는 해당 내용을 보고 어떤 경우에 어떤 에러가 발생되는지 쉽게 파악할 수 있게 될 것입니다. | ||
|
|
||
| <img width= "100%" src="https://i.imgur.com/1sNI8yt.png"></img> | ||
|
|
||
| <br> | ||
|
|
||
| 또한 `public` 메서드의 경우 필요한 전제조건을 문서화해서 남겨 놓아야 하고, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 자바 언어의 public 이라면, 스위프트의 경우에는
도 문서화해서 남겨 놓아야겠습니다(UIKit나 Foundation을 보고 말씀드립니다). 이처럼 Swift의 경우에는 어떤 접근 제한자의 메서드를 문서화해야 하는지 같이 내용 추가되면 좋을 것 같아요. |
||
| 한 클래스에 정의된 많은 메서드가 같은 이유로 같은 예외를 던진다면 그 **예외를 클래스 설명에 추가하는 방법**도 고려해보라고 이야기하고 있습니다. | ||
|
|
||
| 클래스에 대한 주석 또한 위와 같은 방법으로 작성할 수 있으므로 사용자가 더욱 효과적으로 클래스를 사용할 수 있겠습니다. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=> 철자 수정하였습니다! 😁