org.sogrey.frame.global.AppException.java Source code

Java tutorial

Introduction

Here is the source code for org.sogrey.frame.global.AppException.java

Source

/*
 * 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 org.sogrey.frame.global;

import android.text.TextUtils;

import org.apache.http.conn.ConnectTimeoutException;

import java.net.ConnectException;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;

//import org.apache.http.client.ClientProtocolException;
//import org.apache.http.conn.HttpHostConnectException;

/**
 *  2012 amsoft.cn
 * ??AbAppException.java
 * ??.
 */
public class AppException extends Exception {

    /**
     * The Constant serialVersionUID.
     */
    private static final long serialVersionUID = 1;

    /**
     * ?.
     */
    private String msg = null;

    /**
     * 
     *
     * @param e
     *         
     */
    public AppException(Exception e) {
        super();

        try {
            //         if( e instanceof HttpHostConnectException) {
            //            msg = AppConfig.UNKNOWN_HOST_EXCEPTION;
            //         }else
            if (e instanceof ConnectException) {
                msg = AppConfig.CONNECT_EXCEPTION;
            } else if (e instanceof ConnectTimeoutException) {
                msg = AppConfig.CONNECT_EXCEPTION;
            } else if (e instanceof UnknownHostException) {
                msg = AppConfig.UNKNOWN_HOST_EXCEPTION;
            } else if (e instanceof SocketException) {
                msg = AppConfig.SOCKET_EXCEPTION;
            } else if (e instanceof SocketTimeoutException) {
                msg = AppConfig.SOCKET_TIMEOUT_EXCEPTION;
            } else if (e instanceof NullPointerException) {
                msg = AppConfig.NULL_POINTER_EXCEPTION;
            }
            //         else if( e instanceof ClientProtocolException) {
            //            msg = AppConfig.CLIENTP_ROTOCOL_EXCEPTION;
            //         }
            else {
                if (e == null || TextUtils.isEmpty(e.getMessage())) {
                    msg = AppConfig.NULL_MESSAGE_EXCEPTION;
                } else {
                    msg = e.getMessage();
                }
            }
        } catch (Exception e1) {
        }

    }

    /**
     * ?.
     *
     * @param message
     *         ?
     */
    public AppException(String message) {
        super(message);
        msg = message;
    }

    /**
     * ????
     *
     * @return the message
     */
    @Override
    public String getMessage() {
        return msg;
    }

}