Volley

网络请求错误返回
VolleyError


package com.android.volley;/** Exception style class encapsulating Volley errors */
@SuppressWarnings("serial")
public class VolleyError extends Exception {public final NetworkResponse networkResponse;private long networkTimeMs;public VolleyError() {networkResponse = null;}public VolleyError(NetworkResponse response) {networkResponse = response;}public VolleyError(String exceptionMessage) {super(exceptionMessage);networkResponse = null;}public VolleyError(String exceptionMessage, Throwable reason) {super(exceptionMessage, reason);networkResponse = null;}public VolleyError(Throwable cause) {super(cause);networkResponse = null;}/* package */ void setNetworkTimeMs(long networkTimeMs) {this.networkTimeMs = networkTimeMs;}public long getNetworkTimeMs() {return networkTimeMs;}
}


可以看到Volley这个类,写了5个平时可能用到的错误返回的构造方法。源码很清除,具体就不解释了。但是我搜索这个类被引用的地方的时候,发现很多类都引用了这个类,volley就47个java文件,有这么多类竟然引用到VolleyError,说明Volley设计的非常的简洁,而且严谨,一个不多一个不少,都充分的去利用每个类的价值,应该是极高的构架师来构架的volley这个项目。(试想平时我们自己写的一个接口或者抽象类,写的有这样的简单吗?而且被很多的类(不同的类型的类)引用)。

服务器错误类 ServerError,ServerError.class继承自VolleyError.class

package com.android.volley;
/** Indicates that the server responded with an error response. */
@SuppressWarnings("serial")
public class ServerError extends VolleyError {public ServerError(NetworkResponse networkResponse) {super(networkResponse);}public ServerError() {super();}
}

解析错误类 ParseError

package com.android.volley;/** Indicates that the server's response could not be parsed. */
@SuppressWarnings("serial")
public class ParseError extends VolleyError {public ParseError() {}public ParseError(NetworkResponse networkResponse) {super(networkResponse);}public ParseError(Throwable cause) {super(cause);}
}

网络错误类 NetworkError

package com.android.volley;/** Indicates that there was a network error when performing a Volley request. */
@SuppressWarnings("serial")
public class NetworkError extends VolleyError {public NetworkError() {super();}public NetworkError(Throwable cause) {super(cause);}public NetworkError(NetworkResponse networkResponse) {super(networkResponse);}
}

AuthFailureError 认证失败类

package com.android.volley;import android.content.Intent;/** Error indicating that there was an authentication failure when performing a Request. */
@SuppressWarnings("serial")
public class AuthFailureError extends VolleyError {/** An intent that can be used to resolve this exception. (Brings up the password dialog.) */private Intent mResolutionIntent;public AuthFailureError() {}public AuthFailureError(Intent intent) {mResolutionIntent = intent;}public AuthFailureError(NetworkResponse response) {super(response);}public AuthFailureError(String message) {super(message);}public AuthFailureError(String message, Exception reason) {super(message, reason);}public Intent getResolutionIntent() {return mResolutionIntent;}@Overridepublic String getMessage() {if (mResolutionIntent != null) {return "User needs to (re)enter credentials.";}return super.getMessage();}
}

时间错误类

package com.android.volley;/** Indicates that the connection or the socket timed out. */
@SuppressWarnings("serial")
public class TimeoutError extends VolleyError {}

…还有一个子类没有列出
我在想为什么VolleyError 和子类没有用接口了,而是用类来表示
我看了下子类被用到的地方,发现基本上都是可以new Object()即用到了实例,这个平时开发中需要去学习的。

对于VolleyError:
Java中接口不能被实例化的,所以VolleyError继承类。

Volley源码学习2--Error类相关推荐

  1. JDK11源码学习05 | HashMap类

    JDK11源码学习05 | HashMap类 JDK11源码学习01 | Map接口 JDK11源码学习02 | AbstractMap抽象类 JDK11源码学习03 | Serializable接口 ...

  2. Mono源码学习笔记:Console类(四)

    NullStream 类 (internal class) 以下就是 mcs/class/corlib/System.IO/NullStream.cs: 01: namespace System.IO ...

  3. JAVA源码学习(一)——String类

    一.String类的不可变性 源码: public final class String//final修饰类,不可继承 private final char value[];//String类实际返回 ...

  4. Volley源码学习2--cache类

    这是一些cache缓存的基本接口,没有身体特别的地方 package com.android.volley;import java.util.Collections; import java.util ...

  5. Volley源码学习3--log类

    VolleyLog工具类 这个类对系统Log做了一些封装,支持release不打印log,而且可以VolleyLog.d("xxxx");已经一个d% s%格式的log packa ...

  6. Mono源码学习笔记:Console类(三)

    Buffer 类 (public static class) 以下就是 mcs/class/corlib/System/Buffer.cs: 001: // 002: // System.Buffer ...

  7. Volley源码学习1--volley结构图

    volley结构图 从这张图可以了解volley整个工作原理. 1 当客户端发生一个请求的时候 2 会先从缓存中去查找,是不是有缓存 3 如果请求不能从缓存中得到服务,那么它将被放置在网络队列中.第一 ...

  8. 基于Qt5.14.2和mingw的Qt源码学习(三) — 元对象系统简介及moc工具是如何保存类属性和方法的

    基于Qt5.14.2和mingw的Qt源码学习(三) - 元对象系统简介及moc工具是如何保存类属性和方法的 一.什么是元对象系统 1.元对象系统目的 2.实现元对象系统的关键 3.元对象系统的其他一 ...

  9. Volley 源码解析之图片请求

    一.前言 上篇文章我们分析了网络请求,这篇文章分析对图片的处理操作,如果没看上一篇,可以先看上一篇文章Volley 源码解析之网络请求.Volley 不仅仅对请求网络数据作了良好的封装,还封装了对图片 ...

最新文章

  1. 思维dp ---- 复杂状态找中间状态作为dp状态 1552F - Telepanting
  2. NGUI_Depth
  3. ThreadGroup
  4. 对python来说、一个模块就是一个文件-python导入自定义模块和包
  5. iOS 集成银联支付swift
  6. 权益证明协议中的拜占庭容错
  7. 46. Permutations
  8. oracle获取序列并赋值,Oracle中序列的使用
  9. 原型界面演示浏览器设置:ie6浏览器需将《高级》选项卡中“允许活动内容在我的计算机上的文件中运行”勾选...
  10. 【BZOJ4653】区间,离散化+线段树
  11. android父布局的右侧,相对布局(RelativeLayout)的控件运用
  12. html5 日历 仿ios,一款完整的蓝白风格HTML5日历应用程序
  13. C# LeetCode刷题 - LeetCode 148. Sort List 解题报告(归并排序小结)
  14. 时尚圈美女撰文主攻方向
  15. vue全家桶指的是哪些?
  16. 使用Cubic定制ubuntu系统
  17. Vue进阶(壹佰):当前页面刷新并重载页面数据
  18. Linux RHCE常用命令,概念复习
  19. 曲径通幽——遇见未知的你
  20. adbpg 使用 insert onconflict 覆盖写入数据

热门文章

  1. 循环计数_倒计数器:CountDownLatch | 循环栅栏:CyclicBarrier
  2. linux shell 版本信息,查看各种Linux系统版本信息的Shell命令
  3. OpenGL学习(二)第一个OpenGL程序,绘制三角形
  4. 项目管理工具project软件学习(一) - 项目信息设置
  5. 使用JQuery的Blazor日期选择器组件
  6. Microsoft Blazor Platz.SqlForms开源——使用架构生成器设计和维护SQL Server数据库
  7. (五)使用生成对抗网络 (GAN)生成新的时装设计
  8. .NET Core 3.0中的Cookie身份验证
  9. 以编程方式在ASP.NET MVC中使用多个HTML Select控件
  10. Fedora 31 及以后版本将不再支持 32 位内核已实锤