File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed
1-js/08-error-handling/1-try-catch/1-finally-or-code-after Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -2,11 +2,11 @@ importance: 5
2
2
3
3
---
4
4
5
- # Finally or just the code?
5
+ # 在 ` finally ` 中执行,还是在直接放在代码后面
6
6
7
- Compare the two code fragments.
7
+ 比较下面两个代码片段。
8
8
9
- 1 . The first one uses ` finally ` to execute the code after ` try..catch ` :
9
+ 1 . 用 ` finally ` 执行 ` try..catch ` 之后的代码:
10
10
11
11
``` js
12
12
try {
@@ -19,7 +19,7 @@ Compare the two code fragments.
19
19
*/ ! *
20
20
}
21
21
```
22
- 2. The second fragment puts the cleaning right after ` try..catch` :
22
+ 2. 第二个代码片段,把清空工作空间的代码放在 ` try..catch` 之后,但并不包裹在 ` finally ` 里面。
23
23
24
24
` ` ` js
25
25
try {
@@ -33,6 +33,6 @@ Compare the two code fragments.
33
33
*/!*
34
34
` ` `
35
35
36
- We definitely need the cleanup after the work has started, doesn ' t matter if there was an error or not.
36
+ 我们只是需要在代码执行完之后,清除工作空间,而不管是不是在执行的过程中遇到异常。
37
37
38
- Is there an advantage here in using `finally` or both code fragments are equal? If there is such an advantage, then give an example when it matters.
38
+ 那么,是用 ` finally` 好呢还是两种方式都一样?如果哪种更好,请举例说明在什么情况下它会更好?
You can’t perform that action at this time.
0 commit comments