From 25e02254fecf87f894d90ffe44f737ff0cea8e27 Mon Sep 17 00:00:00 2001 From: guzoff Date: Wed, 15 May 2019 22:32:55 +0300 Subject: [PATCH] Update async & performance/ch3.md (fix error type) I think that the error type mentioned in text should be changed from TypeError to ReferenceError (or maybe some 'foo' variable should be defined in global or function scope to get actually TypeError). --- async & performance/ch3.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/async & performance/ch3.md b/async & performance/ch3.md index fbbc0442a..f88c37b8f 100644 --- a/async & performance/ch3.md +++ b/async & performance/ch3.md @@ -593,7 +593,7 @@ p.then( // never gets here :( }, function rejected(err){ - // `err` will be a `TypeError` exception object + // `err` will be a `ReferenceError` exception object // from the `foo.bar()` line. } ); @@ -621,7 +621,7 @@ p.then( ); ``` -Wait, that makes it seem like the exception from `foo.bar()` really did get swallowed. Never fear, it didn't. But something deeper is wrong, which is that we've failed to listen for it. The `p.then(..)` call itself returns another promise, and it's *that* promise that will be rejected with the `TypeError` exception. +Wait, that makes it seem like the exception from `foo.bar()` really did get swallowed. Never fear, it didn't. But something deeper is wrong, which is that we've failed to listen for it. The `p.then(..)` call itself returns another promise, and it's *that* promise that will be rejected with the `ReferenceError` exception. Why couldn't it just call the error handler we have defined there? Seems like a logical behavior on the surface. But it would violate the fundamental principle that Promises are **immutable** once resolved. `p` was already fulfilled to the value `42`, so it can't later be changed to a rejection just because there's an error in observing `p`'s resolution.