Java tutorial
/* * Copyright (C) 2012 www.amsoft.cn * * 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 com.yajun.yunxin.global; import android.text.TextUtils; import com.google.gson.JsonSyntaxException; import org.apache.http.conn.ConnectTimeoutException; import java.net.ConnectException; import java.net.SocketException; import java.net.SocketTimeoutException; import java.net.UnknownHostException; // TODO: Auto-generated Javadoc /** * Created by Administrator on 2016/9/4. * ??. */ public class HttpException extends Exception { /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1; /** The Constant CONNECTEXCEPTION. */ public String CONNECT_EXCEPTION = ""; /** The Constant UNKNOWNHOSTEXCEPTION. */ public String UNKNOWN_HOST_EXCEPTION = "?"; /** The Constant SOCKETEXCEPTION. */ public String SOCKET_EXCEPTION = "?"; /** The Constant SOCKETTIMEOUTEXCEPTION. */ public String SOCKET_TIMEOUT_EXCEPTION = "?"; /** The Constant NULLPOINTEREXCEPTION. */ public String NULL_POINTER_EXCEPTION = "?"; /** The Constant NULLMESSAGEEXCEPTION. */ public String NULL_MESSAGE_EXCEPTION = "?"; /** The Constant CLIENTPROTOCOLEXCEPTION. */ public String CLIENT_PROTOCOL_EXCEPTION = "Http?"; /** The Constant JSON_PALL_EXCEPTION. */ public final String JSON_PALL_EXCEPTION = "json?"; /** ??. */ public String MISSING_PARAMETERS = "??"; /** The Constant REMOTESERVICEEXCEPTION. */ public String REMOTE_SERVICE_EXCEPTION = "?"; /** ?. */ public String NOT_FOUND_EXCEPTION = "?404"; /** ???. */ public String FORBIDDEN_EXCEPTION = "???"; /** . */ public String UNTREATED_EXCEPTION = "?"; /** ?. */ private String msg = null; /** * . * * @param e */ public HttpException(Exception e) { super(); try { if (e instanceof ConnectException) { msg = CONNECT_EXCEPTION; } else if (e instanceof ConnectTimeoutException) { msg = CONNECT_EXCEPTION; } else if (e instanceof UnknownHostException) { msg = UNKNOWN_HOST_EXCEPTION; } else if (e instanceof SocketException) { msg = SOCKET_EXCEPTION; } else if (e instanceof SocketTimeoutException) { msg = SOCKET_TIMEOUT_EXCEPTION; } else if (e instanceof NullPointerException) { msg = NULL_POINTER_EXCEPTION; } else if (e instanceof JsonSyntaxException) { msg = JSON_PALL_EXCEPTION; } else { if (e == null || TextUtils.isEmpty(e.getMessage())) { msg = NULL_MESSAGE_EXCEPTION; } else { msg = e.getMessage(); } } } catch (Exception e1) { } } /** * ?. * * @param message ? */ public HttpException(String message) { super(message); msg = message; } /** * ????. * * @return the message */ @Override public String getMessage() { return msg; } }