简体   繁体   English

android volley网络库中的异常处理

[英]Exception handling in android volley networking library

如何在排序中处理异常,它是否在构建中提供异常处理机制或者我们需要单独处理它?

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. 当您在Volley创建请求对象时,您需要指定一个错误侦听器,当执行请求时出现错误时,Volley会调用该侦听器的onErrorResponse回调方法传递VolleyError对象的实例。

The following is the list of exceptions in Volley: 以下是Volley中的例外列表:

AuthFailureError — If you are trying to do Http Basic authentication then this error is most likely to come. AuthFailureError - 如果您尝试执行Http Basic身份验证,则最有可能出现此错误。

NetworkError — Socket disconnection, server down, DNS issues might result in this error. NetworkError - 套接字断开连接,服务器关闭,DNS问题可能导致此错误。

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. NoConnectionError -到NetworkError类似,但火灾时,该设备没有连接互联网,您的错误处理逻辑可俱乐部NetworkErrorNoConnectionError在一起,把它们与此类似。

ParseError — While using JsonObjectRequest or JsonArrayRequest if the received JSON is malformed then this exception will be generated. ParseError - 如果收到的JSON格式JsonArrayRequest则使用JsonObjectRequestJsonArrayRequest时会生成此异常。 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. ServerError - 服务器响应错误,很可能是4xx或5xx HTTP状态代码。

TimeoutError — Socket timeout, either server is too busy to handle the request or there is some network latency issue. TimeoutError - 套接字超时,服务器太忙而无法处理请求或存在一些网络延迟问题。 By default, Volley times out the request after 2.5 seconds, use a RetryPolicy if you are consistently getting this error. 默认情况下, Volley在2.5秒后超时请求,如果您一直收到此错误,请使用RetryPolicy。

Source: http://arnab.ch/blog/2013/08/asynchronous-http-requests-in-android-using-volley/ 资料来源: http//arnab.ch/blog/2013/08/asynchronous-http-requests-in-android-using-volley/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM