【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"); } }
南京小黄猫教育
是专业的计算机编程培训,包含面向少儿的Scratch,面向青少年的Python,面向就业的Java、C/C++及Web前端技术。微信:wuwy233
地址:南京市江宁区月华路12-6弘阳上院