`
ember_319
  • 浏览: 20640 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

学习Roller4中的Exception

    博客分类:
  • Java
 
阅读更多

Roller4中,所有的异常都直接或间接得是RollerException的子类,从它的代码中可以看到怎样构建异常的StackTrace结构。

/**
 * Base Roller exception class.
 */
public abstract class RollerException extends Exception {
    
    private final Throwable mRootCause;
    
    
    /**
     * Construct emtpy exception object.
     */
    public RollerException() {
        super();
        mRootCause = null;
    }
    
    
    /**
     * Construct RollerException with message string.
     * @param s Error message string.
     */
    public RollerException(String s) {
        super(s);
        mRootCause = null;
    }
    
    
    /**
     * Construct RollerException, wrapping existing throwable.
     * @param s Error message
     * @param t Existing connection to wrap.
     */
    public RollerException(String s, Throwable t) {
        super(s);
        mRootCause = t;
    }
    
    
    /**
     * Construct RollerException, wrapping existing throwable.
     * @param t Existing exception to be wrapped.
     */
    public RollerException(Throwable t) {
        mRootCause = t;
    }
    
    
    /**
     * Get root cause object, or null if none.
     * @return Root cause or null if none.
     */
    public Throwable getRootCause() {
        return mRootCause;
    }
    
    
    /**
     * Get root cause message.
     * @return Root cause message.
     */
    public String getRootCauseMessage() {
        String rcmessage = null;
        if (getRootCause()!=null) {
            if (getRootCause().getCause()!=null) {
                rcmessage = getRootCause().getCause().getMessage();
            }
            rcmessage = (rcmessage == null) ? getRootCause().getMessage() : rcmessage;
            rcmessage = (rcmessage == null) ? super.getMessage() : rcmessage;
            rcmessage = (rcmessage == null) ? "NONE" : rcmessage;
        }
        return rcmessage;
    }
    
    
    /**
     * Print stack trace for exception and for root cause exception if htere is one.
     * @see java.lang.Throwable#printStackTrace()
     */
    public void printStackTrace() {
        super.printStackTrace();
        if (mRootCause != null) {
            System.out.println("--- ROOT CAUSE ---");
            mRootCause.printStackTrace();
        }
    }
    
    
    /**
     * Print stack trace for exception and for root cause exception if htere is one.
     * @param s Stream to print to.
     */
    public void printStackTrace(PrintStream s) {
        super.printStackTrace(s);
        if (mRootCause != null) {
            s.println("--- ROOT CAUSE ---");
            mRootCause.printStackTrace(s);
        }
    }
    
    
    /**
     * Print stack trace for exception and for root cause exception if htere is one.
     * @param s Writer to write to.
     */
    public void printStackTrace(PrintWriter s) {
        super.printStackTrace(s);
        if (null != mRootCause) {
            s.println("--- ROOT CAUSE ---");
            mRootCause.printStackTrace(s);
        }
    }
    
}
 待续...

1
0
分享到:
评论

相关推荐

    Apache Roller

    Apache Roller是一个全功能,多用户和组博客服务器,适合大型和小型博客网站。它运行一个Java Web应用程序应该能够运行在任何Java EE服务器和关系数据库。目前,Apache Roller能很好的支持Tomcat和MySQL...仅供学习参考

    roller

    NULL 博文链接:https://moving200x.iteye.com/blog/1749902

    开源Java博客Roller v5.0 for tomcat.zip

    Roller 是一个全功能的多用户博客平台,于2002年首发,采用Java语言开发,设计精巧,源代码是很好的学习资料。它支持weblogging应有的特性如:评论功能,所见即所得HTML编辑,TrackBack,提供页面模板,RSS ...

    教育科研-学习工具-Roller卷轴式剃须组件.zip

    教育科研-学习工具-Roller卷轴式剃须组件.zip

    Safety evaluation of table liner for vertical roller mill

    Safety evaluation of table liner for vertical roller mill by modified fatigue limit

    Roller.part4

    该软件是一个开源的BLOG系统,是目前的最新版。 其中用到的技术有:SPRING HIBERNATE STRUTS等。 一共4部分

    roller-part01

    apache-roller-srapaapache-roller-srcche-roller-srccapache-rolaapache-roller-srcpache-roller-srcler-srcapapache-roller-srcache-roller-srcapache-roller-src

    Roller4.0的另外一套cas简单解决方案

    毕竟网上关于roller4的资料少之又少.对于cas的单点集成就更是少的可怜.我试验了一下roller自带的security.xml配置的cas方案.简直报错的夸张.根本没发用.roller使用的是acegi的用户验证框架.我自己下了一套acegi配置...

    roller-part2

    apache-rollapachapache-roller-srce-roller-srcer-srcapache-rolleapacapache-roller-srche-roller-srcr-srcapache-roapache-roller-srcller-srcapache-roller-src

    apache-roller-src

    apache-roller-src apache-roller-src apache-roller-src apache-roller-src apache-roller-src apache-roller-src apache-roller-src apache-roller-src apache-roller-src apache-roller-src

    roller安装

    NULL 博文链接:https://jarorwar.iteye.com/blog/554942

    开源Java博客Roller v5.0 for tomcat

    Roller 是一个全功能的多用户博客平台,于2002年首发,采用Java语言开发,设计精巧,源代码是很好的学习资料。它支持weblogging应有的特性如:评论功能,所见即所得HTML编辑,TrackBack,提供页面模板,RSS ...

    roller-weblogger.rar

    weblogging 设计比较精巧,是很好的学习资料。它支持weblogging应有的特性如:评论功能,所见即所得HTML编辑,TrackBack,提供页面模板,RSS syndication,blogroll管理和提供一个XML-RPC 接口。 最主要是其开源

    roller安装指南电子书

    apache roller安装指南电子书 翻译官方roller安装帮助文档

Global site tag (gtag.js) - Google Analytics