-
Notifications
You must be signed in to change notification settings - Fork 179
Error handling, "try...catch" #225
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
Merged
+240
−240
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
b44acfa
Initial changes
Purusah 85cf52b
Next step translated
Purusah 488e6d2
Improvments
Purusah bd91071
Images translated
Purusah 992ff4a
Almost the end
Purusah ef9a300
Finalization
Purusah 75f5447
Clean up
Purusah e494e21
Fix image translation
Purusah e5731a7
Task name translation
Purusah 7113dd3
Typo fixes
Purusah de26d2f
More typo fixes
Purusah e6d83ff
Merge pull request #1 from Purusah/translate/try-catch-flow
Purusah acdc7a0
Added review fixes
Purusah 180fd3b
Adjust word order to general style
Purusah 1c657e3
Merge pull request #2 from Purusah/translate/try-catch-flow
Purusah e267ed2
Small fixes
tarasyyyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
28 changes: 14 additions & 14 deletions
28
1-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 @@ | ||
The difference becomes obvious when we look at the code inside a function. | ||
Різниця стає очевидною, якщо ми подивимося на код всередині функції. | ||
|
||
The behavior is different if there's a "jump out" of `try...catch`. | ||
Поведінка відрізнятиметься, якщо код «раптово вийде» з блоку `try...catch`. | ||
|
||
For instance, when there's a `return` inside `try...catch`. The `finally` clause works in case of *any* exit from `try...catch`, even via the `return` statement: right after `try...catch` is done, but before the calling code gets the control. | ||
Наприклад, якщо всередині `try...catch` є `return`. Блок `finally` спрацює для "будь-якого" виходу з `try...catch`, навіть за допомогою `return` -- одразу після виходу з блоку `try...catch`, але перед передачею контролю кодові, що викликав цю функцію. | ||
|
||
```js run | ||
function f() { | ||
try { | ||
alert('start'); | ||
alert('початок'); | ||
*!* | ||
return "result"; | ||
return "результат"; | ||
*/!* | ||
} catch (err) { | ||
/// ... | ||
} finally { | ||
alert('cleanup!'); | ||
alert('очищення!'); | ||
} | ||
} | ||
|
||
f(); // cleanup! | ||
f(); // очищення! | ||
``` | ||
|
||
...Or when there's a `throw`, like here: | ||
...Або якщо є `throw`: | ||
|
||
```js run | ||
function f() { | ||
try { | ||
alert('start'); | ||
throw new Error("an error"); | ||
alert('початок'); | ||
throw new Error("помилка"); | ||
} catch (err) { | ||
// ... | ||
if("can't handle the error") { | ||
if("не можу обробити помилку") { | ||
*!* | ||
throw err; | ||
*/!* | ||
} | ||
|
||
} finally { | ||
alert('cleanup!') | ||
alert('очищення!') | ||
} | ||
} | ||
|
||
f(); // cleanup! | ||
f(); // очищення! | ||
``` | ||
|
||
It's `finally` that guarantees the cleanup here. If we just put the code at the end of `f`, it wouldn't run in these situations. | ||
`finally` гарантує очищення. Очищення не спрацює, якщо ми просто додамо код в кінці функції `f`. |
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
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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.
Uh oh!
There was an error while loading. Please reload this page.