Skip to content

Commit

Permalink
Don't Panic: Remove main panic
Browse files Browse the repository at this point in the history
  • Loading branch information
xxjwxc committed Sep 15, 2020
1 parent 8f80b50 commit 634c571
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ change.md
# 2020-06-17
- map和切片的联合指导
# 2020-09-15
- Remove main panic
-->

# [uber-go/guide](https://github.com/uber-go/guide) 的中文翻译
Expand All @@ -94,7 +97,7 @@ change.md

## 版本

- 当前更新版本:2020-06-17 版本地址:[commit:#97](https://github.com/uber-go/guide/commit/fdb233143f1276f33ccba1372588c3b9290d00f1)
- 当前更新版本:2020-09-15 版本地址:[commit:#105](https://github.com/uber-go/guide/commit/9c691f1a46fad810619683511fb129b20268bc4c)
- 如果您发现任何更新、问题或改进,请随时 fork 和 PR
- Please feel free to fork and PR if you find any updates, issues or improvement.

Expand Down Expand Up @@ -1090,41 +1093,34 @@ fine. -->
<tr><td>

```go
func foo(bar string) {
if len(bar) == 0 {
panic("bar must not be empty")
func run(args []string) {
if len(args) == 0 {
panic("an argument is required")
}
// ...
}

func main() {
if len(os.Args) != 2 {
fmt.Println("USAGE: foo <bar>")
os.Exit(1)
}
foo(os.Args[1])
run(os.Args[1:])
}
```

</td><td>

```go
func foo(bar string) error {
if len(bar) == 0 {
return errors.New("bar must not be empty")
func run(args []string) error {
if len(args) == 0 {
return errors.New("an argument is required")
}
// ...
return nil
}

func main() {
if len(os.Args) != 2 {
fmt.Println("USAGE: foo <bar>")
if err := run(os.Args[1:]); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
if err := foo(os.Args[1]); err != nil {
panic(err)
}
}
```

Expand Down

0 comments on commit 634c571

Please sign in to comment.