⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 errorbean.java

📁 以前做的一个j2ee的项目
💻 JAVA
字号:
package gov.gdlt.ssgly.taxweb.mbean;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.sql.SQLException;
import javax.servlet.ServletException;
import java.io.Serializable;
import java.util.Properties;
import java.io.FileInputStream;
import java.net.URL;
import java.io.InputStream;
import gov.gdlt.ssgly.taxcore.comm.util.FileURL;
import gov.gdlt.ssgly.taxcore.comm.log.LogWritter;

public class ErrorBean implements Serializable {


    public static final String ERROR_PROPS = "error.properties";
    private Object stackTrace;
    private Properties settings = new Properties();

    public String getStackTrace(Throwable ex) {

        StringWriter sw = new StringWriter();

        PrintWriter pw = new PrintWriter(sw);

        fillStackTrace(ex, pw);

        return sw.toString();
    }

    private static void fillStackTrace(Throwable t, PrintWriter w) {
        if (t == null) {
            return;
        }
        t.printStackTrace(w);

        if (t instanceof ServletException) {
            Throwable cause = ((ServletException) t).getRootCause();
            if (cause != null) {
                w.println("Root cause:");
                fillStackTrace(cause, w);
            }
        } else if (t instanceof SQLException) {
            Throwable cause = ((SQLException) t).getNextException();

            if (cause != null) {
                w.println("Next exception:");
                fillStackTrace(cause, w);
            }
        } else {
            Throwable cause = t.getCause();
            if (cause != null) {
                w.println("Cause:");
                fillStackTrace(cause, w);
            }
        }
    }

    public void setStackTrace(Object stackTrace) {
        this.stackTrace = stackTrace;
    }
/*
    读取error.properties文件
     */
    public  Properties getProperties() {
        Properties props = new Properties();
        InputStream is = null;
        try {
            FileURL fileUrl = new FileURL();
            URL url = fileUrl.getFileURL(ERROR_PROPS);
            is = url.openStream();
            props.load(is);
        } catch (Exception e) {
            props = null;
            System.out.println("没有找到properties文件");
        } finally {
            try {
                if (is != null) {
                    is.close();
                }
            } catch (Exception e) {}

                LogWritter.sysInfo("读取系统错误描述文件: " + this.ERROR_PROPS);

        }

        return props;
    }

}

⌨️ 快捷键说明

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