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
+21-21Lines changed: 21 additions & 21 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -579,19 +579,19 @@ function func() {
579
579
В приведенном выше коде, ошибка всегда выпадает наружу, потому что тут нет блока `catch`. Но `finally` отрабатывает до того, как поток управления выпрыгнет наружу.
580
580
````
581
581
582
-
## Globalcatch
582
+
## Глобальныйcatch
583
583
584
-
```warn header="Environment-specific"
585
-
The information from this section is not a part of the core JavaScript.
584
+
```warn header="Специфично для окружения"
585
+
Информация из данной секции не является часть базового JavaScript.
586
586
```
587
587
588
-
Let's imagine we've got a fatal error outside of`try..catch`, and the script died. Like a programming error or something else terrible.
588
+
Давайте представим, что произошла фатальная ошибка (программная или что-то еще ужасное) снаружи `try..catch`, и скрипт упал.
589
589
590
-
Is there a way to react on such occurrences? We may want to log the error, show something to the user (normally they don't see error messages) etc.
590
+
Существует ли способ отреагировать на такие ситуации? Мы можем захотеть залогировать ошибку, показать что-то пользователю (обычно они не увидят сообщение об ошибке) и т.д.
591
591
592
-
There is none in the specification, but environments usually provide it, because it's really useful. For instance, Node.jshas [process.on('uncaughtException')](https://nodejs.org/api/process.html#process_event_uncaughtexception) for that. And in the browser we can assign a function to special [window.onerror](mdn:api/GlobalEventHandlers/onerror) property. It will run in case of an uncaught error.
592
+
Такого способа нет в спецификации, но обычно окружения предоставляют его, потому что это весьма полезно. Например, в Node.jsдля этого есть [process.on('uncaughtException')](https://nodejs.org/api/process.html#process_event_uncaughtexception). И в браузере мы можем присвоить функцию специальному свойству [window.onerror](mdn:api/GlobalEventHandlers/onerror). Она отработает в случае необработанной ошибки.
alert(`${message}\n At ${line}:${col} of ${url}`);
620
+
alert(`${message}\n В ${line}:${col} на ${url}`);
621
621
};
622
622
*/!*
623
623
624
624
function readData() {
625
-
badFunc(); // Whoops, something went wrong!
625
+
badFunc(); // Ой, что-то пошло не так!
626
626
}
627
627
628
628
readData();
629
629
</script>
630
630
```
631
631
632
-
The role of the global handler `window.onerror`is usually not to recover the script execution --that's probably impossible in case of programming errors, but to send the error message to developers.
632
+
Роль глобального обработчика `window.onerror`обычно заключается не в восстановление выполнения скрипта --это скорее всего невозможно в случае программной ошибки, а в отправке сообщение об ошибке разработчикам.
633
633
634
-
There are also web-services that provide error-logging for such cases, like <https://errorception.com> or <http://www.muscula.com>.
634
+
Существуют также веб-сервисы, которые предоставляют логирование ошибок для таких случаев, такие как <https://errorception.com> или <http://www.muscula.com>.
635
635
636
-
They work like this:
636
+
Они работают так:
637
637
638
-
1. We register at the service and get a piece of JS (or a script URL) from them to insert on pages.
639
-
2. That JS script has a custom `window.onerror` function.
640
-
3. When an error occurs, it sends a network request about it to the service.
641
-
4. We can log in to the service web interface and see errors.
638
+
1.Мы регистрируемся в сервисе и получаем небольшую часть JS (или URL скрипта) от них для вставки на страницы.
639
+
2.В этом JSскрипте есть кастомная `window.onerror`функцию.
640
+
3.Когда возникает ошибка, он отправляет сетевой запрос о ней в сервис.
641
+
4.Мы можем войти в сервисный веб-интерфейс и увидеть ошибки.
0 commit comments