icexceptionhandler.java~2~

来自「java接口(关于java调用动态库」· JAVA~2~ 代码 · 共 65 行

JAVA~2~
65
字号
package com.jysy.taxcore.comm.exception;

import java.util.Properties;
import java.io.InputStream;
import java.io.*;
import java.net.URL;

/**
 * 异常信息处理类
 *
 * <p>Title: ICExceptionHandler</p>
 * <p>Description: 南京地税税控机IC卡编程接口</p>
 * <p>Copyright: Copyright (c) 2004 广东京粤商用技术有限公司</p>
 * <p>Company: 广东京粤商用技术有限公司</p>
 * @author 李志毅
 * @version 1.0
 */
public class ICExceptionHandler {
    /**
     * 根据异常对象,取出异常描述信息
     * @param e  异常对象, 封装了异常信息
     * @return   该异常的描述信息
     */

    public static String getErrorMsg(TaxBaseICException e) {
        Properties props = new Properties();
        String errInfoResources = e.getErrorInfoResources();
        InputStream is = null;
        try {
            String prefix = ".properties";
            errInfoResources = errInfoResources.trim();
            errInfoResources = errInfoResources.substring(0,
                errInfoResources.length() - prefix.length());
            errInfoResources = errInfoResources.replace('.', '/');
            if (!errInfoResources.startsWith("/")) {
                errInfoResources = "/" + errInfoResources;
            }
            errInfoResources += prefix;

            props.load(props.getClass().getResourceAsStream(errInfoResources));
        }
        catch (Exception ex) {
            props = null;
            ex.printStackTrace();
        }
        finally {
            try {
                if (is != null) {
                    is.close();
                }
            }
            catch (Exception ex) {}
        }

        String errMsg = null;
        System.out.println(e.getMessage());
        if (props == null || (errMsg = (props.getProperty(e.getMessage()))) == null) {
            errMsg = "未知异常!";
        }

        return errMsg;
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?