Promise._catch() causes to lost previous result
Opened this issue · 3 comments
SergeyA commented
Promise._catch() causes to lost previous result so the next handler in the chain gets null. See:
public <U> Promise <U> _catch (OnRejected onRejected)
{
if (onRejected == null)
throw new IllegalStateException ("onRejected cannot be null");
return this.then (null, onRejected);
}
Maybe it should be replaced by:
public <U> Promise <U> _catch (OnRejected onRejected)
{
if (onRejected == null)
throw new IllegalStateException ("onRejected cannot be null");
return this.then (v -> Promise.resolve(v), onRejected);
}
Kinchkun commented
Hi,
I have the same issue. Maybe I misunderstand the API?
Example:
Promise.resolve("String")
._catch(rejected(error -> {throw new RuntimeException("Does not occur");}))
.then(resolved(System.out::println));
I create a resolved promise. So the _catch
is not executed. However, the resolved value in the then
is null
.
The solution of SergeyA fixed the problem for me.