-
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,38 @@ | ||||||
| # 메서드가 던지는 모든 예외를 문서화하라 | ||||||
|
|
||||||
| 이번 아이템에서는 각 메서드가 던지는 예외를 문서화하는데 충분한 시간을 쏟아야 한다고 설명하고 있습니다. | ||||||
|
|
||||||
| 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()`를 호출하는 사용자는 해당 내용을 보고 어떤 경우에 어떤 에러가 발생되는지 쉽게 파악할 수 있게 될 것입니다. | ||||||
|
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.
Suggested change
=> 철자 수정하였습니다! 😁 |
||||||
|
|
||||||
| <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의 경우에는 어떤 접근 제한자의 메서드를 문서화해야 하는지 같이 내용 추가되면 좋을 것 같아요. |
||||||
| 한 클래스에 정의된 많은 메서드가 같은 이유로 같은 예외를 던진다면 그 **예외를 클래스 설명에 추가하는 방법**도 고려해보라고 이야기하고 있습니다. | ||||||
|
|
||||||
| 클래스에 대한 주석 또한 위와 같은 방법으로 작성할 수 있으므로 사용자가 더욱 효과적으로 클래스를 사용할 수 있겠습니다. | ||||||
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.
item74. 가 빠져있어요.!!
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.
오우 수정하도록 하겠습니다 👍🏻