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/11-async/04-promise-error-handling/article.md
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -166,11 +166,11 @@ new Promise(function() {
166
166
167
167
In case of an error, the promise becomes rejected, and the execution should jump to the closest rejection handler. But there is none. So the error gets "stuck". There's no code to handle it.
168
168
169
-
In practice, just like with regular unhandled errors in code, it means that something has terribly gone wrong.
169
+
In practice, just like with regular unhandled errors in code, it means that something has gone terribly wrong.
170
170
171
-
What happens when a regular error occurs and is not caught by `try..catch`? The script dies with a message in console. Similar thing happens with unhandled promise rejections.
171
+
What happens when a regular error occurs and is not caught by `try..catch`? The script dies with a message in the console. A similar thing happens with unhandled promise rejections.
172
172
173
-
JavaScript engine tracks such rejections and generates a global error in that case. You can see it in the console if you run the example above.
173
+
The JavaScript engine tracks such rejections and generates a global error in that case. You can see it in the console if you run the example above.
174
174
175
175
In the browser we can catch such errors using the event `unhandledrejection`:
176
176
@@ -201,4 +201,4 @@ In non-browser environments like Node.js there are other ways to track unhandled
201
201
-`.catch` handles errors in promises of all kinds: be it a `reject()` call, or an error thrown in a handler.
202
202
- We should place `.catch` exactly in places where we want to handle errors and know how to handle them. The handler should analyze errors (custom error classes help) and rethrow unknown ones (maybe they are programming mistakes).
203
203
- It's ok not to use `.catch` at all, if there's no way to recover from an error.
204
-
- In any case we should have the `unhandledrejection` event handler (for browsers, and analogs for other environments), to track unhandled errors and inform the user (and probably our server) about the them, so that our app never "just dies".
204
+
- In any case we should have the `unhandledrejection` event handler (for browsers, and analogs for other environments) to track unhandled errors and inform the user (and probably our server) about them, so that our app never "just dies".
0 commit comments