auto-value

AutoValue how to call super


@AutoValue
public abstract class MyError extends Throwable {

    public static MyError create(
            Throwable ex,
            MyErrorCode errorCode) {
        return new AutoValue_MyError(ex, errorCode);
    }

    public abstract Throwable getError();

    public abstract MyErrorCode myErrorCode();
}

I use AutoValue to create MyError class and question is how do I do super(ex.getCause()) to pass the actual context. Looks like the generated implementation doesn't do that.


Solution

  • HAS-A relation is better than IS-A relation. So MyError class should not extend Throwable class.

    I think we can't call super(ex.getCause()).

    AutoValue creates immutable object using Builder pattern. See the issue on Github auto repository getError() method will return Throwable object and then you can call getClause() method on the same.