Edited
I have a custom Exception class MyException
public class MyException extends RunTimeException{
public MyException()
{
super();
}
public MyException(String message)
{
super(message);
}
public MyException(Exception e)
{
super(e);
}
}
now whenever an exception is raised I catch it in MyException and throw it back to the parent function. I am facing an issue as I am using AsyncHttpClient and it raises an exception in onFailure as it is raised by the server.
This is how I am making HTTP Request and trying to handle Exception.
AsyncHttpClient client = new AsyncHttpClient();
client.setTimeout(TIMEOUT);
try {
client.post(mainActivity,
PATH, new StringEntity(requiredDataForRequest),
"application/json", new AsyncHttpResponseHandler() {
@Override
public void onSuccess(String response) {
}
@Override
public void onFailure(int arg0, Header[] arg1,
byte[] arg2, Throwable e) throws MyException {
throw new MyException("Error Description Here!");
}
});
} catch (MyException e) {
log.debug("Exception: " + e.getMessage());
}
Now it is Crashing my app on throw new MyException and not catching it in catch block. Any idea or help would be appreciated.