您的位置:首页 > 编程语言 > Java开发

Java 日看一类(31)之IO包中的InvalidClassException异常类和IOError异常类

2018-03-22 09:50 260 查看
InvalidClassException类无引入包
继承了ObjectStreamException

该类的类头注释如下:
/**
* Thrown when the Serialization runtime detects one of the following
* problems with a Class.
* <UL>
* <LI> The serial version of the class does not match that of the class
* descriptor read from the stream
* <LI> The class contains unknown datatypes
* <LI> The class does not have an accessible no-arg constructor
* </UL>
*
* @author unascribed
* @since JDK1.1
*/大意如下:
当下列问题在序列化出现时该异常被抛出:
    序列化版本和从流中读取出类描述符的版本不匹配

    类包含了不知名的数据类型

    该类不含有可以无参数访问的构造函数

该类含有如下的成员变量:
序列化ID:private static final long serialVersionUID = -4333316296251054416L;无效的类型名public String classname;

该类含有如下的成员方法:
构造函数(上传错误原因public InvalidClassException(String reason) {
super(reason);
}构造函数(上传错误原因和错误类名public InvalidClassException(String cname, String reason) {
super(reason);
classname = cname;
}生成消息和类名(如果类名存在
public String getMessage() {
if (classname == null)
return super.getMessage();
else
return classname + "; " + super.getMessage();
}

该类和InvalidObjectException有一定的相似之处,也有一些不同(类和实例的错误不同),遇到时候请仔细分析

IOError无引入包
继承自Error类

该类的类头注释如下:/**
* Thrown when a serious I/O error has occurred.
*
* @author Xueming Shen
* @since 1.6
*/大意如下:
当发生严重的IO错误时该类被抛出

该类含有如下的成员变量:
序列化ID:private static final long serialVersionUID = 67100927991680413L;

该类含有如下的成员方法:
构造函数构造带有指定 cause 的新 IOError 实例。IOError 是使用详细消息 (cause==null ? null :cause.toString())(它通常包含 cause 的类和详细消息)创建的):public IOError(Throwable cause) {
super(cause);
}

该类被抛出的时候一般意味着出了比较大的问题,注意抛出时候的注释
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: