rookieDeveloper rookieDeveloper -4 years ago 266
Android Question

handle timeout exception in loopj

I am having error in handling the timeout exception in


public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {

Log.e("DB", String.valueOf(error));
Log.e("DB", String.valueOf(error.getCause() instanceof ConnectTimeoutException));

first log gives the response Connect to / timed out

while second log gives

I want to handle the timeout exception how should I do it?

Answer Source

Your 2nd log operation is based on


which is null or not a ConnectTimeoutException, while within your first log operation you are directly using the Throwable given in method parameter.

Therefore, I would suggest to use the error and not error.getCause() to handle the ConnectTimeoutException.

Log.e("DB", String.valueOf(error instanceof ConnectTimeoutException)); // --> Should be true now
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download