Custom Retrofit ErrorHandler gives UndeclaredThrowableException

android, retrofit

Solution

If you are returning a checked exception you need to declare it on the interface.

interface MyService {
  Foo doFoo() throws MyNetworkError;
}

Problem

Based on this post How should I handle "No internet connection" with Retrofit on Android I made a custom `ErrorHandler` ``` private static class CustomErrorHandler implements ErrorHandler { @Override public Throwable handleError(RetrofitError error) { if (error.isNetworkError()) { return new MyNetworkError(); } return error.getCause(); } } ``` And now my application crashes and I get this: ``` java.lang.reflect.UndeclaredThrowableException ``` Is there some configuration needed for the adapter? Using `Retrofit 1.6.0` with `OkHttp 2.0.0` Thanks.

Original source

Related problems