You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/10-error-handling/1-try-catch/article.md
+10-29Lines changed: 10 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -354,25 +354,17 @@ try {
354
354
355
355
بالطبع ، كل شيء ممكن! المبرمجون يرتكبون الأخطاء. حتى في المرافق المفتوحة المصدر التي يستخدمها الملايين لعقود - فجأة يمكن اكتشاف خطأ يؤدي إلى اختراق رهيب.
356
356
357
-
<<<<<<<HEAD
358
-
في حالتنا هذه, `try..catch` المقصود لالتقاط أخطاء "البيانات غير صحيحة".ولكن بطبيعتها ، `catch` يحصل على *كل* الأخطاء من `try`. هنا يحصل على خطأ غير متوقع, ولكن لا يزال يظهر `"JSON Error"`. هذا خطأ ويجعل أيضًا تصحيح التعليمات البرمجية أكثر صعوبة.
357
+
في حالتنا هذه, `try..catch` المقصود لالتقاط أخطاء "البيانات غير صحيحة".ولكن بطبيعتها ، `catch` يحصل على *كل* الأخطاء من `try`. هنا يحصل على خطأ غير متوقع, ولكن لا يزال يظهر `"JSON Error"`. هذا خطأ ويجعل أيضًا تصحيح التعليمات البرمجية أكثر صعوبة.القاعدة بسيطة:
359
358
360
-
لحسن الحظ ، يمكننا معرفة الخطأ الذي تحصلنا عليه ، على سبيل المثال من `name`:
361
-
=======
362
-
In our case, `try..catch` is placed to catch"incorrect data"errors. But by its nature, `catch` gets *all* errors from `try`. Here it gets an unexpected error, but still shows the same `"JSON Error"`message. That's wrong and also makes the code more difficult to debug.
363
-
364
-
To avoid such problems, we can employ the "rethrowing" technique. The rule is simple:
365
-
366
-
**Catch should only process errors that it knows and "rethrow" all others.**
359
+
**يجب أن يقوم Catch بمعالجة الأخطاء التي يعرفها و "إعادة رمي" كل الآخرين فقط.**
367
360
368
-
The "rethrowing" technique can be explained in more detail as:
361
+
يمكن شرح تقنية "إعادة الرمي" بمزيد من التفصيل على النحو التالي:
369
362
370
-
1. Catch gets all errors.
371
-
2. In the `catch(err) {...}` block we analyze the error object `err`.
372
-
2. If we don't know how to handle it, we do`throw err`.
0 commit comments