promises
promises copied to clipboard
Promise._catch() causes to lost previous result
Promise._catch() causes to lost previous result so the next handler in the chain gets null. See: https://github.com/onehilltech/promises/blob/e5b76c56d372acfb200e97b37ecde0e5146f54ee/promises-jvm/src/main/java/com/onehilltech/promises/Promise.java#L520
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);
}
@SergeyA Do you have an example that illustrates this problem?
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.
@Kinchkun I am pretty sure that if this is a problem, then it was an oversight on my part and the proposed fix will address the problem. Could you create a test case for this scenario, and submit a pull request?