异常的核心类Throwable
编程技术  /  houtizong 发布于 3年前   213
package com.natsu;/** * java异常体系的核心 * @author huangqun * */public class Throwable {/** * 详细的异常信息 */private String detailMessage; /** * 异常实体 默认是本身 */private Throwable cause = this; public Throwable(String message) {this.detailMessage = message;}public Throwable(String message, Throwable cause) {this.detailMessage = message;this.cause = cause;}public Throwable(Throwable cause) {this.detailMessage = (cause == null ? null : cause.toString());this.cause = cause;}/** * 获取异常详细信息 常用方法 */public String getMessage() {return this.detailMessage;}public String toString() {String name = this.getClass().getName();String message = getMessage();return (message != null) ? (name + ": " + message) : name; }public static void main(String[] args) {Throwable e = new Throwable("异常信息是。。。。");System.out.println(e.getMessage());Throwable e1 = new Throwable(e);System.out.println(e1.getMessage());Throwable e2 = new Throwable("新的异常信息", e);System.out.println(e2.getMessage());}
package com.natus;/** * 业务异常类, * 必须填写业务的错误信息. * 错误信息是可以直接给用户看的. * */public class BussinessException extends Exception {private static final long serialVersionUID = -3591382539768191631L;public BussinessException(String message) {super(message);}public BussinessException(String message, Throwable cause) {super(message, cause);}}
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接