- Notifications
You must be signed in to change notification settings - Fork44
Error handling, "try...catch"#202
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
khachoangpt wants to merge2 commits intojavascript-tutorial:masterChoose a base branch fromkhachoangpt:error-handling
base:master
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.
Uh oh!
There was an error while loading.Please reload this page.
Open
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
28 changes: 14 additions & 14 deletions1-js/10-error-handling/1-try-catch/1-finally-or-code-after/solution.md
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 |
|---|---|---|
| @@ -1,47 +1,47 @@ | ||
| Sự khác biệt trở nên rõ ràng khi chúng ta xem xétcodebên trong một hàm. | ||
| Cách phản ứng sẽ khác nhau nếu có hành vi "nhảy ra" của `try...catch`. | ||
| Ví dụ, khi có một `return`bên trong`try...catch`.Mệnh đề`finally`hoạt động trên *bất kỳ* lối thoát nào khỏi`try...catch`,ngay cả khi thoát qua câu lệnh`return`: ngay sau khi`try...catch`kết thúc thực thi, nhưng trước khi gọi codegiành quyền kiểm soát. | ||
| ```js run | ||
| function f() { | ||
| try { | ||
| alert('bắt đâù'); | ||
| *!* | ||
| return "kết quả"; | ||
| */!* | ||
| } catch (err) { | ||
| /// ... | ||
| } finally { | ||
| alert('dọn dẹp!'); | ||
| } | ||
| } | ||
| f(); //dọn dẹp! | ||
| ``` | ||
| ...Hoặc khi có một `throw`,như thế này: | ||
| ```js run | ||
| function f() { | ||
| try { | ||
| alert('bắt đầu'); | ||
| throw new Error("một lỗi"); | ||
| } catch (err) { | ||
| // ... | ||
| if("không thể xử lý lỗi") { | ||
| *!* | ||
| throw err; | ||
| */!* | ||
| } | ||
| } finally { | ||
| alert('dọn dẹp!') | ||
| } | ||
| } | ||
| f(); //dọn dẹp! | ||
| ``` | ||
| `finally`ở đây đảm bảo việc dọn dẹp. Nếu chúng ta chỉ đặt codeở cuối hàm`f`,thì nó sẽ không chạy trong những tình huống này. |
26 changes: 13 additions & 13 deletions1-js/10-error-handling/1-try-catch/1-finally-or-code-after/task.md
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 |
|---|---|---|
| @@ -1,38 +1,38 @@ | ||
| mức độ quan trọng: 5 | ||
| --- | ||
| # Finallyhay chỉ dùng code? | ||
| So sánh hai đoạncodedươí đây. | ||
| 1.Đoạn code đầu tiên sử dụng`finally`để thực thi codesau khi `try...catch`: | ||
| ```js | ||
| try { | ||
| công việc | ||
| } catch (err) { | ||
| xử lý lỗi | ||
| } finally { | ||
| *!* | ||
| dọn dẹp không gian làm việc | ||
| */!* | ||
| } | ||
| ``` | ||
| 2.Đoạn code thứ hai đặt code dọn dẹp ngay sau `try...catch`: | ||
| ```js | ||
| try { | ||
| công việc | ||
| } catch (err) { | ||
| xử lý lỗi | ||
| } | ||
| *!* | ||
| dọn dẹp không gian làm việc | ||
| */!* | ||
| ``` | ||
| Chúng tôi chắc chắn cần phải dọn dẹp sau khi làm việc, bất kể có lỗi trong quá trình làm việc hay không. | ||
| Có lợi thế nào khi sử dụng `finally`ở đây không hay cả hai đoạncodelà tương đương nhau? Nếu có một lợi thế nào đó ở đây, xin vui lòng cho một ví dụ nếu cần thiết. |
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
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.