okaywit / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Add Futures.addCallback overload to support a failure callback interface with typed exception #1489

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
More or less like this:

Futures.addCallback(future, 
    new FutureSuccessCallback<Result>() {
        @Override
        public void onSuccess(Result result) {          
        },
    new FutureFailureCallback<MyFutureExceptionWrapper>() {
        @Override
        public void onFailure(MyFutureExceptionWrapper myFutureExceptionWrapper) {          
        }
}, MoreExecutors. ....);

public class FutureExceptionWrapper extends Throwable {
    public FutureException() {
    }
    public FutureException(Throwable t) {
        super(t);
    }
}

public class MyFutureExceptionWrapper extends FutureExceptionWrapper {  
    private int errorCode

    public  MyFutureException(Throwable t) {
        this(t, -1);
    }

    public  MyFutureException(Throwable t, int errorCode) {
        super(t);
        this.errorCode = errorCode;
    }
}

Internally the api should do the following before calling onFailure

FutureExceptionWrapper ex = null

if (throwable instanceof MyFutureExceptionWrapper)
    ex = (MyFutureExceptionWrapper) throwable;
else
    ex = new MyFutureExceptionWrapper(throwable);   

Original issue reported on code.google.com by itaitai2...@yahoo.com on 30 Jul 2013 at 11:06

GoogleCodeExporter commented 9 years ago

Original comment by kevinb@google.com on 20 Nov 2013 at 8:52

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<issue id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:12

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:17

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08