Vishwanath.M Vishwanath.M - 11 months ago 106
Android Question

Exception handling in android volley networking library

How about exception handling in volley, does it provide exception handling mechanism in build or we need to handle it separately?

Answer Source

when you create a request object in Volley you need to specify an error listener, Volley invokes the onErrorResponse callback method of that listener passing an instance of the VolleyError object when there is an error while performing the request.

The following is the list of exceptions in Volley:

AuthFailureError — If you are trying to do Http Basic authentication then this error is most likely to come.

NetworkError — Socket disconnection, server down, DNS issues might result in this error.

NoConnectionError — Similar to NetworkError, but fires when the device does not have Internet connection, your error handling logic can club NetworkError and NoConnectionError together and treat them similarly.

ParseError — While using JsonObjectRequest or JsonArrayRequest if the received JSON is malformed then this exception will be generated. If you get this error then it is a problem that should be fixed instead of being handled.

ServerError — The server responded with an error, most likely with 4xx or 5xx HTTP status codes.

TimeoutError — Socket timeout, either server is too busy to handle the request or there is some network latency issue. By default, Volley times out the request after 2.5 seconds, use a RetryPolicy if you are consistently getting this error.