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); }
该类被抛出的时候一般意味着出了比较大的问题,注意抛出时候的注释

本文解析了InvalidClassException和IOError两个异常类。InvalidClassException在序列化过程中因版本不匹配、未知数据类型或构造函数问题而抛出。IOError则在出现严重IO错误时抛出。
341

被折叠的 条评论
为什么被折叠?



