All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hadoopz.MyDroidLib.exceptions.BaseExceptionHandler Maven / Gradle / Ivy

There is a newer version: 1.0.62
Show newest version
/*
 * Copyright 2017 jw362j.
 *
 * 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.hadoopz.MyDroidLib.exceptions;

/**
 *
 * @author jw362j
 */
import java.lang.Thread.UncaughtExceptionHandler;
//import java.text.DateFormat;

/**
 * 系统异常处理基类
 *
 * @author blue
 *
 */
public abstract class BaseExceptionHandler implements UncaughtExceptionHandler {

    public static final String TAG = "CrashHandler";

//    protected static final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);

    /**
     * 未捕获异常跳转
     *
     * @param thread
     * @param ex
     */
    @Override
    public void uncaughtException(Thread thread, final Throwable ex) {
        // 如果正确处理了未捕获异常
        if (handleException(ex)) {
            try {
                // 如果处理了,让程序继续运行3秒再退出,保证错误日志的保存
                Thread.sleep(3000);
            } catch (InterruptedException e) {
            }

            // 退出程序
            android.os.Process.killProcess(android.os.Process.myPid());
            System.exit(1);
        }
    }

    /**
     *
     * 自定义错误处理,收集错误信息 发送错误报告等操作均在此完成. 开发者可以根据自己的情况来自定义异常处理逻辑
     *
     * @param ex
     * @return
     *
     */
    public abstract boolean handleException(Throwable ex);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy