Skip to content

Commit 6a5f119

Browse files
committed
Translate Global catch part
1 parent f2671de commit 6a5f119

1 file changed

Lines changed: 21 additions & 21 deletions

File tree

1-js/10-error-handling/1-try-catch/article.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -579,19 +579,19 @@ function func() {
579579
В приведенном выше коде, ошибка всегда выпадает наружу, потому что тут нет блока `catch`. Но `finally` отрабатывает до того, как поток управления выпрыгнет наружу.
580580
````
581581

582-
## Global catch
582+
## Глобальный catch
583583

584-
```warn header="Environment-specific"
585-
The information from this section is not a part of the core JavaScript.
584+
```warn header="Специфично для окружения"
585+
Информация из данной секции не является часть базового JavaScript.
586586
```
587587

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`, и скрипт упал.
589589

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+
Существует ли способ отреагировать на такие ситуации? Мы можем захотеть залогировать ошибку, показать что-то пользователю (обычно они не увидят сообщение об ошибке) и т.д.
591591

592-
There is none in the specification, but environments usually provide it, because it's really useful. For instance, Node.js has [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). Она отработает в случае необработанной ошибки.
593593

594-
The syntax:
594+
Синтаксис:
595595

596596
```js
597597
window.onerror = function(message, url, line, col, error) {
@@ -600,45 +600,45 @@ window.onerror = function(message, url, line, col, error) {
600600
```
601601

602602
`message`
603-
: Error message.
603+
: Сообщение об ошибке.
604604

605605
`url`
606-
: URL of the script where error happened.
606+
: URL скрипта, в котором произошла ошибка.
607607

608608
`line`, `col`
609-
: Line and column numbers where error happened.
609+
: Номера строки и столбца, в которых произошла ошибка.
610610

611611
`error`
612-
: Error object.
612+
: Объект ошибки.
613613

614-
For instance:
614+
Пример:
615615

616616
```html run untrusted refresh height=1
617617
<script>
618618
*!*
619619
window.onerror = function(message, url, line, col, error) {
620-
alert(`${message}\n At ${line}:${col} of ${url}`);
620+
alert(`${message}\n В ${line}:${col} на ${url}`);
621621
};
622622
*/!*
623623
624624
function readData() {
625-
badFunc(); // Whoops, something went wrong!
625+
badFunc(); // Ой, что-то пошло не так!
626626
}
627627
628628
readData();
629629
</script>
630630
```
631631

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` обычно заключается не в восстановление выполнения скрипта -- это скорее всего невозможно в случае программной ошибки, а в отправке сообщение об ошибке разработчикам.
633633

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>.
635635

636-
They work like this:
636+
Они работают так:
637637

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. Мы можем войти в сервисный веб-интерфейс и увидеть ошибки.
642642

643643
## Summary
644644

0 commit comments

Comments
 (0)