Skip to content
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
@youurayy

Description

@youurayy

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:

exceptionHandler(e);

  1. line 365: the Error is correctly passed up the promise chain: deferred.reject(e);
  2. 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).

Possibly related; #7992, #13653

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions