Hey everyone,
I was looking for an idiom or paradigm on how to handle HTTP errors.
Basically,
I have an AsyncTask that runs in a background thread, that calls a static
method of mine called executeRequest().
This is all done in the doInBackground() part. There are two types of
exceptions that be thrown by executeRequest(). An IOException for all
communication errors and a ServerErrorResponse exception which is my own
exception. This can occur if for example the client sent something bad to
the server, the whole HTTP worked but the server complained (perhaps I
passed an invalid parameter or id).
So, what I have done is wrap the result in a "result object" of my own.
In onPostExecute() I check if the result was failed and then I try to handle
it in the UI thread. However, I now have to start doing
Excpetion e = result.getException();
if (e != null) {
if (e instanceof IOException) //network error {
//handle network error here
} else if (e instanceOf ServerErrorResponseException) {
//handle server error response here
}
As you can see this is becoming annoying, For every new exception I have to
check it using instanceof. Is there a way around it or a design I could
follow to avoid this? I want the excpetions to be processed in the UI thread
in case I show a dialog box or something to the user.
Thanks!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en