Skip to content

Commit 2e942ad

Browse files
committed
translate 10.1 try-catch to AR
1 parent 7a4c4e9 commit 2e942ad

4 files changed

Lines changed: 219 additions & 218 deletions

File tree

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
The difference becomes obvious when we look at the code inside a function.
1+
يصبح الفرق واضحًا عندما ننظر إلى الكود داخل دالة.
22

3-
The behavior is different if there's a "jump out" of `try..catch`.
3+
يختلف السلوك إذا كان هناك "خروج" من `try..catch`.
44

5-
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.
5+
على سبيل المثال ، عندما يكون هناك `return` داخل `try..catch`. يعمل `finally` في حالة *أي* خروج من `try..catch`, حتى عبر عبارة `return`: مباشرة بعد الانتهاء من `try..catch`, ولكن قبل أن يحصل الكود الذي قمنا بالاتصال به على التحكم.
66

77
```js run
88
function f() {
99
try {
10-
alert('start');
10+
alert('إبدء');
1111
*!*
12-
return "result";
12+
return "النتيجة";
1313
*/!*
1414
} catch (e) {
1515
/// ...
1616
} finally {
17-
alert('cleanup!');
17+
alert('نظف!');
1818
}
1919
}
2020

21-
f(); // cleanup!
21+
f(); // نظف!
2222
```
2323

24-
...Or when there's a `throw`, like here:
24+
...أو عندما يكون هناك `throw`, مثلما هو الحال هنا:
2525

2626
```js run
2727
function f() {
2828
try {
29-
alert('start');
29+
alert('إبدء');
3030
throw new Error("an error");
3131
} catch (e) {
3232
// ...
@@ -37,11 +37,11 @@ function f() {
3737
}
3838

3939
} finally {
40-
alert('cleanup!')
40+
alert('نظف!')
4141
}
4242
}
4343

44-
f(); // cleanup!
44+
f(); // نظف!
4545
```
4646

47-
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.
47+
يضمن `finally` التنظيف. إذا وضعنا الكود في نهاية `f`, فلن يتم تشغيلها في هذه المواقف.

1-js/10-error-handling/1-try-catch/1-finally-or-code-after/task.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,37 @@ importance: 5
22

33
---
44

5-
# Finally or just the code?
5+
# Finally أم الكود فقط؟
66

7-
Compare the two code fragments.
7+
قارن بين جزئي الكود.
88

9-
1. The first one uses `finally` to execute the code after `try..catch`:
9+
1. يستخدم الأول `finally` لتشغيل الكود بعد `try..catch`:
1010

1111
```js
1212
try {
13-
work work
13+
إعمل إعمل
1414
} catch (e) {
15-
handle errors
15+
معالجة الأخطاء
1616
} finally {
1717
*!*
18-
cleanup the working space
18+
تنظيف مكان العمل
1919
*/!*
2020
}
2121
```
22-
2. The second fragment puts the cleaning right after `try..catch`:
22+
2. الجزء الثاني يضع التنظيف مباشرة بعد `try..catch`:
2323

2424
```js
2525
try {
26-
work work
26+
إعمل إعمل
2727
} catch (e) {
28-
handle errors
28+
معالجة الأخطاء
2929
}
3030
3131
*!*
32-
cleanup the working space
32+
تنظيف مكان العمل
3333
*/!*
3434
```
3535

36-
We definitely need the cleanup after the work, doesn't matter if there was an error or not.
36+
نحن بالتأكيد بحاجة إلى التنظيف بعد العمل ، لا يهم إذا كان هناك خطأ أم لا.
3737

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` أم أن جزئي الكود متساويان؟ إذا كان هناك مثل هذه الميزة ، فقم بإعطاء مثال عندما يكزن مهم.

0 commit comments

Comments
 (0)