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
3. زمانی که اروری رخ میدهد، این تابع درباره آن ارور، یک درخواست شبکه را به سرویس ارسال میکند.
642
642
4. ما میتوانیم وارد رابط وب سرویس شویم و ارورها را ببینیم.
643
643
644
-
## Summary
644
+
## خلاصه
645
645
646
-
The`try...catch`construct allows to handle runtime errors. It literally allows to "try" running the code and "catch" errors that may occur in it.
646
+
ساختار`try...catch`مدیریت ارورهای زمان اجرا را ممکن میسازد. این ساختار به طور لفظی اجازه میدهد که اجرای کد را «امتحان کنیم (try)» و ارورهایی که ممکن است درون آن رخ بدهند را «بگیریم (catch)».
647
647
648
-
The syntax is:
648
+
سینتکس آن:
649
649
650
650
```js
651
651
try {
652
-
//run this code
652
+
//این کد را اجرا کن
653
653
} catch (err) {
654
-
//if an error happened, then jump here
655
-
//err is the error object
654
+
//اگر اروری رخ داد، سپس به اینجا بپر
655
+
//شیء ارور است err
656
656
} finally {
657
-
//do in any case after try/catch
657
+
//این قسمت را انجام بده try/catch در هر صورت، بعد از
658
658
}
659
659
```
660
660
661
-
There may be no `catch`section or no `finally`, so shorter constructs `try...catch`and`try...finally`are also valid.
661
+
ممکن است قسمت `catch`یا `finally` وجود نداشته باشد پس ساختارهای کوتاهتر `try...catch`و`try...finally`هم معتبر هستند.
662
662
663
-
Error objects have following properties:
663
+
شیءهای ارور ویژگیهای پایین را دارند:
664
664
665
-
-`message` -- the human-readable error message.
666
-
-`name` -- the string with error name (error constructor name).
667
-
-`stack` (non-standard, but well-supported) -- the stack at the moment of error creation.
665
+
-`message` -- پیام ارور که برای انسان قابل خواندن است.
666
+
-`name` -- رشته حاوی اسم ارور (اسم تابع سازنده ارور)
667
+
-`stack` (استاندارد نیست، اما به خوبی پشتیبانی میشود) -- پشتهای که در لحظه ایجاد ارور وجود دارد.
668
668
669
-
If an error object is not needed, we can omit it by using `catch {`instead of`catch (err) {`.
669
+
اگر شیء ارور نیاز نباشد، ما میتوانیم با استفاده از `catch {`به جای`catch (err) {` آن را حذف کنیم.
670
670
671
-
We can also generate our own errors using the `throw`operator. Technically, the argument of`throw`can be anything, but usually it's an error object inheriting from the built-in `Error`class. More on extending errors in the next chapter.
671
+
همچنین میتوانیم با استفاده از عملگر `throw`ارورهای خودمان را ایجاد کنیم. از لحاظ فنی، آرگومان`throw`میتواند هر چیزی باشد اما معمولا یک شیء ارور است که از کلاس درونساخت `Error`ارثبری میکند. اطلاعات بیشتری درباره تعمیم دادن ارورها در فصل بعدی وجود دارد.
672
672
673
-
*Rethrowing* is a very important pattern of error handling: a `catch`block usually expects and knows how to handle the particular error type, so it should rethrow errors it doesn't know.
673
+
*پرتاب دوباره (rethrowing)* یک الگوی بسیار مهم در مدیریت ارور است: یک بلوک `catch`معمولا توقع یک نوع ارور خاص را دارد و میتواند چجوری آن را مدیریت کند پس باید ارورهایی که آنها را نمیشناسد را دوباره پرتاب کند.
674
674
675
-
Even if we don't have `try...catch`, most environments allow us to setup a "global" error handler to catch errors that "fall out". In-browser, that's`window.onerror`.
675
+
حتی اگر ما `try...catch` نداشته باشیم، اکثر محیطهای اجرا به ما اجازه میدهند که یک کنترلکننده ارور «گلوبال» را برای گرفتن ارورهایی که «بیرون میافتند» بسازیم. در مرورگر`window.onerror` همان کنترلکننده است.
0 commit comments