|
|
/*
|
|
|
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
|
*
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
* You may obtain a copy of the License at
|
|
|
*
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
*
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
* See the License for the specific language governing permissions and
|
|
|
* limitations under the License.
|
|
|
*/
|
|
|
|
|
|
package net.micode.notes.gtask.exception;
|
|
|
|
|
|
// NetworkFailureException类继承自Exception,属于受检异常(Checked Exception),意味着在代码中使用到可能抛出该异常的方法时,
|
|
|
// 必须显式地使用try-catch语句进行捕获处理,或者在方法声明中使用throws关键字将异常继续向上抛出,用于表示在网络相关操作出现失败情况时的异常类型。
|
|
|
public class NetworkFailureException extends Exception {
|
|
|
// 用于实现Java序列化机制的版本号,保证在序列化和反序列化过程中对象的兼容性,这里是一个固定的长整型值。
|
|
|
private static final long serialVersionUID = 2107610287180234136L;
|
|
|
|
|
|
// 默认构造函数,调用父类(Exception)的默认构造函数,不传入任何特定的错误信息,创建一个简单的异常实例,通常在不需要详细错误描述时使用。
|
|
|
public NetworkFailureException() {
|
|
|
super();
|
|
|
}
|
|
|
|
|
|
// 构造函数,接受一个字符串参数,用于指定具体的错误信息内容,调用父类(Exception)的对应构造函数,将错误信息传递给父类构造函数进行初始化。
|
|
|
// 这样在抛出该异常后,捕获异常的代码可以通过获取异常信息来了解网络操作失败的具体原因。
|
|
|
public NetworkFailureException(String paramString) {
|
|
|
super(paramString);
|
|
|
}
|
|
|
|
|
|
// 构造函数,接受一个字符串参数(用于指定具体的错误信息内容)和一个Throwable类型的参数(表示导致当前异常的根源异常,可能是另一个更低层的异常),
|
|
|
// 调用父类(Exception)的对应构造函数,将错误信息和根源异常传递给父类构造函数进行初始化。
|
|
|
// 方便在异常传播过程中保留原始异常信息,便于更准确地进行问题排查和调试,例如网络请求底层出现IOException等异常时,可以将其作为根源异常传递上来。
|
|
|
public NetworkFailureException(String paramString, Throwable paramThrowable) {
|
|
|
super(paramString, paramThrowable);
|
|
|
}
|
|
|
} |