Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promises do not throw unhandled exceptions #128

Closed
SerafimArts opened this issue Aug 16, 2018 · 3 comments
Closed

Promises do not throw unhandled exceptions #128

SerafimArts opened this issue Aug 16, 2018 · 3 comments

Comments

@SerafimArts
Copy link

SerafimArts commented Aug 16, 2018

It seems to me that all unhandled exceptions (for example, without ->otherwise) should be thrown out but this does not happen. Those. In fact, any exceptions impossible to intercept.

I will cite as an example another language where such a class is already implemented and where behaviour is different.

Code sample

ReactPHP (~2.7)

use React\Promise\Deferred;

$deferred = new Deferred();

$deferred->promise()->then(function(): void {
    throw new \Exception('Example');
});

$deferred->resolve();

A similar JS example:

let p = new Promise((c) => {
  setTimeout(() => c(), 1000);
});

p.then(() => { throw new Error(); });

Expected

Uncaught Exception: Example in ...

Actual

ReactPHP: Nothing

JS: Uncaught (in promise) Error ...

@sz-po
Copy link

sz-po commented Jan 12, 2019

Why this ticket was closed? This behavior is intentional?

@WyriHaximus
Copy link
Member

@szymon-podeszwa done rethrows unhandled promises:

use React\Promise\Deferred;

$deferred = new Deferred();

$deferred->promise()->then(function(): void {
    throw new \Exception('Example');
})->done();

$deferred->resolve();

@clue
Copy link
Member

clue commented Jun 8, 2022

Duplicate of #87

@clue clue marked this as a duplicate of #87 Jun 8, 2022
@clue clue closed this as not planned Won't fix, can't repro, duplicate, stale Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants