This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
$q: Control flow duplication (forking) when uncaught error is handled in .then() #14745
Closed
Description
Triggered when:
$q.resolve().then(function() {
throw new Error();
}).catch(function(e) {
// ok, but the catch-all handler also receives `e` (incorrect)
});
Correctly handled when:
$q.resolve().then(function() {
try {
throw new Error();
}
catch(e) {
return $q.reject(e);
}
}).catch(function(e) {
// ok, and the catch-all handler has not been activated (correct)
});
Relevant code:
Line 366 in c9dffde
- line 365: the Error is correctly passed up the promise chain:
deferred.reject(e);
- line 366: the Error is also passed to the
exceptionHandler(e);
, which effectively forks the control flow, if the Promise chain in 1. was not ignored.
Normally this is not a ciritical issue, since exceptionHandler()
is usually used to just print errors to the console, however correctly the error would make it to the exceptionHandler()
only if it was not ignored by the deferred.reject(e);
chain (which, I'm not sure if it's even feasible to implement).