import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
public class AbAppException extends Exception {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 1;
/** 异常消息. */
private String msg = null;
/**
* 构造异常类.
*
* @param e 异常
*/
public AbAppException(Exception e) {
super();
try {
if (e instanceof ConnectException) {
msg = AbConstant.CONNECTEXCEPTION;
}else if (e instanceof UnknownHostException) {
msg = AbConstant.UNKNOWNHOSTEXCEPTION;
}else if (e instanceof SocketException) {
msg = AbConstant.SOCKETEXCEPTION;
}else if (e instanceof SocketTimeoutException) {
msg = AbConstant.SOCKETTIMEOUTEXCEPTION;
}else if( e instanceof NullPointerException) {
msg = AbConstant.NULLPOINTEREXCEPTION;
}else {
if (e == null || AbStrUtil.isEmpty(e.getMessage())) {
msg = AbConstant.NULLMESSAGEEXCEPTION;
}else{
msg = e.getMessage();
}
}
} catch (Exception e1) {
}
}
/**
* 用一个消息构造异常类.
*
* @param message 异常的消息
*/
public AbAppException(String message) {
super(message);
msg = message;
}
/**
* 描述:获取异常信息.
*
* @return the message
*/
@Override
public String getMessage() {
return msg;
}
}
public class AbConstant {
/** 返回码:成功. */
public static final int RESULRCODE_OK = 0;
/** 返回码:失败. */
public static final int RESULRCODE_ERROR = -1;
/** 连接失败的HTTP返回码. */
public static final int CONNECT_FAILURE_CODE = 600;
/** 连接失败的HTTP返回码. */
public static final int CONNECT_TIMEOUT_CODE = 601;
/** 响应失败的HTTP返回码. */
public static final int RESPONSE_TIMEOUT_CODE = 602;
/** 未处理的HTTP返回码. */
public static final int UNTREATED_CODE = 900;
public static final String CONNECTEXCEPTION = "无法连接到网络";
public static final String UNKNOWNHOSTEXCEPTION = "连接远程地址失败";
public static final String SOCKETEXCEPTION = "网络连接出错,请重试";
public static final String SOCKETTIMEOUTEXCEPTION = "连接超时,请重试";
public static final String NULLPOINTEREXCEPTION = "抱歉,远程服务出错了";
public static final String NULLMESSAGEEXCEPTION = "抱歉,程序出错了";
public static final String CLIENTPROTOCOLEXCEPTION = "Http请求参数错误";
/** 参数个数不够. */
public static final String MISSINGPARAMETERS = "参数没有包含足够的值";
}