您当前的位置: 首页 >  Java

柳鲲鹏

暂无认证

  • 0浏览

    0关注

    4642博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

JAVA中抓异常的办法

柳鲲鹏 发布时间:2019-05-28 06:21:44 ,浏览量:0

  前几天有人说软件出错了,又不知道哪里出错。然后吾就想自己抓异常。

  昨天终于闲了下来,于是就重操旧业。

public class UnExceptionHandler implements Thread.UncaughtExceptionHandler
{

private static UnExceptionHandler exceptionHandler;
private static long lastTime;
private static long File logFile;

public static UnCatchHandler getInstance()
{
    if(mUnCatchHandler == null)
    {
        synchronized (UnCatchHandler.class)
        {
            exceptionHandler = new UnExceptionHandler();
            Thread.setDefaultUncaughtExceptionHandler(exceptionHandler);
            lastTime = System.current();
            logFile = new File();
        }
    }
    return exceptionHandler;
}

private UnCatchHandler(Context context)
{
    //
}


/**
 * 保存异常
 * @param t
 * @param e
 */
@Override
public void uncaughtException(Thread t, Throwable e)
{
    //时间控制,文件大小控制
    try
    {
        BufferedWriter writer = new BufferedWriter(new FileWriter(logFile));
        witer.write(time);
        for (ele : e.get())
        {
             writer.write();
        }
        writer.close();
    }
    catch (Exception ex)
    {
        ex.printStackTrace();
    }
}

 

关注
打赏
1665724893
查看更多评论
立即登录/注册

微信扫码登录

0.0663s