Skip to content

Commit 0a3931c

Browse files
committed
Don't ignore caught errors
1 parent 0d37d16 commit 0a3931c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

README-zh-CN.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,15 +1990,19 @@ process (in Node), and notifying you in the console with a stack trace.
19901990
抛出错误是一件好事情! 他们意味着当你的程序有错时运行时可以成功确认, 并且通过停止执行当前堆栈
19911991
上的函数来让你知道, 结束当前进程(在 Node 中), 在控制台中用一个堆栈跟踪提示你。
19921992

1993-
### Don't ignore caught errors
1993+
### 不要忽略捕捉到的错误
19941994
Doing nothing with a caught error doesn't give you the ability to ever fix
19951995
or react to said error. Logging the error to the console (`console.log`)
19961996
isn't much better as often times it can get lost in a sea of things printed
19971997
to the console. If you wrap any bit of code in a `try/catch` it means you
19981998
think an error may occur there and therefore you should have a plan,
19991999
or create a code path, for when it occurs.
20002000

2001-
**Bad:**
2001+
对捕捉到的错误不做任何处理不能给你修复错误或者响应错误的能力。 向控制台记录错误 (`console.log`)
2002+
也不怎么好, 因为往往会丢失在海量的控制台输出中。 如果你把任意一段代码用 `try/catch` 包装那就
2003+
意味着你想到这里可能会错, 因此你应该有个修复计划, 或者当错误发生时有一个代码路径。
2004+
2005+
**不好的:**
20022006
```javascript
20032007
try {
20042008
functionThatMightThrow();
@@ -2007,7 +2011,7 @@ try {
20072011
}
20082012
```
20092013

2010-
**Good:**
2014+
**好的:**
20112015
```javascript
20122016
try {
20132017
functionThatMightThrow();

0 commit comments

Comments
 (0)