【Java】自定义异常

 

package com.littlecat.cbb.exception;

public class LittleCatException extends RuntimeException
{
    private static final long serialVersionUID = 1L;
    private String errorCode;

    public LittleCatException(String message)
    {
        super(message);
    }

    public LittleCatException(String errorCode, String message)
    {
        super(message);
        this.errorCode = errorCode;
    }

    public LittleCatException(String errorCode, String message, Throwable cause)
    {
        super(message, cause);
        this.errorCode = errorCode;
    }

    public LittleCatException(String message, Throwable cause)
    {
        super(message, cause);
    }

    public String getErrorCode()
    {
        return errorCode;
    }

    public void setErrorCode(String errorCode)
    {
        this.errorCode = errorCode;
    }

    //测试代码
    public static void main(String[] args)
    {
        try
        {
            System.out.println(100 / 0);
        }
        catch (Exception e)
        {
            System.out.println(new LittleCatException("haha", e).getMessage());
            throw new LittleCatException("haha", e);
        }
        throw new LittleCatException("haha");
    }
}

 

  

 

posted @ 2018-09-03 20:25  南京小黄猫  阅读(153)  评论(0编辑  收藏  举报