当前位置: 首页 > news >正文

手机网站模板制作教程百度网盘下载速度慢破解方法

手机网站模板制作教程,百度网盘下载速度慢破解方法,成都旅游,linux安装WordPress80端口前言 在Java中处理代码运行异常是常见的技术点之一,我们大部分会使用封装的技巧将异常进行格式化输出,方便反馈给用户界面,也是为了代码复用 看看这行代码是怎么处理异常的 CommonExceptionType.SimpleException.throwEx("用户信息不…

前言

在Java中处理代码运行异常是常见的技术点之一,我们大部分会使用封装的技巧将异常进行格式化输出,方便反馈给用户界面,也是为了代码复用

看看这行代码是怎么处理异常的

CommonExceptionType.SimpleException.throwEx("用户信息不能为空");

1、首先CommonExceptionType是一个枚举类型

public enum CommonExceptionType implements IExceptionType {

   CommonException(),
    SimpleException(-1, "%s", CommonException),

主要的实现还是这个接口:IExceptionType

import java.util.LinkedList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

public interface IExceptionType {
    IExceptionType getParent();

    Integer getErrorCode();

    String getErrorInfoFormat();

    static final ExceptionConsumer consumerLocal = new ExceptionConsumer();

    default IExceptionType initConsumer(Consumer<Exception> consumer) {
        consumerLocal.get().add(consumer);
        return this;
    }
    default IExceptionType initConsumer() {
        consumerLocal.get().add(null);
        return this;
    }

    default RuntimeException throwEx(Object... args) {
        return throwEx((Exception) null, args);
    }

    default RuntimeException throwEx(Throwable e, Object... args) {
        String exceptionInfo = getErrorInfoFormat();
        Integer errorCode = getErrorCode();

        if (args != null && args.length > 0) {
            exceptionInfo = String.format(getErrorInfoFormat(), args);
        }

        CommonException ex;
        if (e == null) {
            ex = new CommonException(exceptionInfo);
        } else {
            try {
                ex = new CommonException(e, exceptionInfo, e.getMessage());
            } catch (Exception exc) {
                ex = new CommonException(e, "%s", e.getMessage());
            }
        }

        ex.setErrorCode(errorCode);
        ex.setExceptionType(this);

        throw ex;
    }
    default <T extends Exception> boolean catchEx(Throwable ex) {
        return catchEx(ex,null);
    }


    default <T extends Exception> boolean catchEx(Throwable ex, Consumer<T> callback) {
        if (ex instanceof CommonException) {
            IExceptionType ce = ((CommonException) ex).getExceptionType();
            if (this.equals(ce) || this.isParent(ce)) {
                if (callback != null) {
                    callback.accept((T) ex);
                }
                return true;
            }
        }
        if (this == CommonExceptionType.CommonException && ex instanceof sunbox.core.exception.CommonException) {
            if (callback != null) {
                callback.accept((T) ex);
            }
            return true;
        }
        if (this == CommonExceptionType.Finally) {
            if (callback != null) {
                callback.accept((T) ex);
            }
            return true;
        }
        return false;
    }
    default boolean isParent(sunbox.core.exception.CommonException ex) {
        if (ex instanceof CommonException) {
            IExceptionType ce = ((CommonException) ex).getExceptionType();
            if (this.equals(ce) || this.isParent(ce)) {
                return true;
            }
        }
        return false;
    }
    default boolean isParent(IExceptionType et) {
        IExceptionType parent = et;
        while (parent != null) {
            if (parent.equals(this)) {
                return true;
            }
            parent = parent.getParent();
        }
        return false;
    }

    default <R, T extends Exception> R tryCatch(Supplier<R> func, Function<T, R> catchFunc) {
        Exception ex = null;
        try {
            if (func != null) {
                return func.get();
            }
            return null;
        } catch (Exception e) {
            if (this.catchEx(e, null)) {
                if (catchFunc != null) {
                    return catchFunc.apply((T) e);
                }
                return null;
            }
            throw e;
        }
    }

    class CommonException extends sunbox.core.exception.CommonException {
        private IExceptionType exceptionType;

        protected CommonException() {
            super("系统异常");
            errorInfo = "系统异常";
        }

        protected CommonException(String errorInfo) {
            super(errorInfo);
            this.errorInfo=errorInfo;
        }

        protected CommonException(String format, Object... args) {
            super(String.format(format, args));
            errorInfo = String.format(format, args);
        }

        protected CommonException(Throwable e, String format, Object... args) {
            super(e, String.format(format, args));
            errorInfo = String.format(format, args);
        }

        protected CommonException(Exception e) {
            super(e);
            errorInfo = "系统异常";
        }

        public IExceptionType getExceptionType() {
            return exceptionType;
        }

        public void setExceptionType(IExceptionType exceptionType) {
            this.exceptionType = exceptionType;
            setErrorCode(exceptionType.getErrorCode());
        }
    }
}
 

import java.util.LinkedList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;public interface IExceptionType {IExceptionType getParent();Integer getErrorCode();String getErrorInfoFormat();static final ExceptionConsumer consumerLocal = new ExceptionConsumer();default IExceptionType initConsumer(Consumer<Exception> consumer) {consumerLocal.get().add(consumer);return this;}default IExceptionType initConsumer() {consumerLocal.get().add(null);return this;}default RuntimeException throwEx(Object... args) {return throwEx((Exception) null, args);}default RuntimeException throwEx(Throwable e, Object... args) {String exceptionInfo = getErrorInfoFormat();Integer errorCode = getErrorCode();if (args != null && args.length > 0) {exceptionInfo = String.format(getErrorInfoFormat(), args);}CommonException ex;if (e == null) {ex = new CommonException(exceptionInfo);} else {try {ex = new CommonException(e, exceptionInfo, e.getMessage());} catch (Exception exc) {ex = new CommonException(e, "%s", e.getMessage());}}ex.setErrorCode(errorCode);ex.setExceptionType(this);throw ex;}default <T extends Exception> boolean catchEx(Throwable ex) {return catchEx(ex,null);}default <T extends Exception> boolean catchEx(Throwable ex, Consumer<T> callback) {if (ex instanceof CommonException) {IExceptionType ce = ((CommonException) ex).getExceptionType();if (this.equals(ce) || this.isParent(ce)) {if (callback != null) {callback.accept((T) ex);}return true;}}if (this == CommonExceptionType.CommonException && ex instanceof sunbox.core.exception.CommonException) {if (callback != null) {callback.accept((T) ex);}return true;}if (this == CommonExceptionType.Finally) {if (callback != null) {callback.accept((T) ex);}return true;}return false;}default boolean isParent(sunbox.core.exception.CommonException ex) {if (ex instanceof CommonException) {IExceptionType ce = ((CommonException) ex).getExceptionType();if (this.equals(ce) || this.isParent(ce)) {return true;}}return false;}default boolean isParent(IExceptionType et) {IExceptionType parent = et;while (parent != null) {if (parent.equals(this)) {return true;}parent = parent.getParent();}return false;}default <R, T extends Exception> R tryCatch(Supplier<R> func, Function<T, R> catchFunc) {Exception ex = null;try {if (func != null) {return func.get();}return null;} catch (Exception e) {if (this.catchEx(e, null)) {if (catchFunc != null) {return catchFunc.apply((T) e);}return null;}throw e;}}class CommonException extends sunbox.core.exception.CommonException {private IExceptionType exceptionType;protected CommonException() {super("系统异常");errorInfo = "系统异常";}protected CommonException(String errorInfo) {super(errorInfo);this.errorInfo=errorInfo;}protected CommonException(String format, Object... args) {super(String.format(format, args));errorInfo = String.format(format, args);}protected CommonException(Throwable e, String format, Object... args) {super(e, String.format(format, args));errorInfo = String.format(format, args);}protected CommonException(Exception e) {super(e);errorInfo = "系统异常";}public IExceptionType getExceptionType() {return exceptionType;}public void setExceptionType(IExceptionType exceptionType) {this.exceptionType = exceptionType;setErrorCode(exceptionType.getErrorCode());}}
}

这里我们可以看到interface里面,不再是单纯函数的定义,还有函数的实现。这是要转变。这样使接口的实现多了一份灵活性,但是如果接口里单纯的只定义函数,没有函数的实现的话,可能代码逻辑和结构更加清晰一些,这也是过去我们学习的interface接口。


文章转载自:
http://aciduria.rjbb.cn
http://successive.rjbb.cn
http://trick.rjbb.cn
http://gagger.rjbb.cn
http://quirkish.rjbb.cn
http://colourway.rjbb.cn
http://fiddleback.rjbb.cn
http://displume.rjbb.cn
http://fragmentary.rjbb.cn
http://orometer.rjbb.cn
http://musicianly.rjbb.cn
http://tyrotoxicon.rjbb.cn
http://marxize.rjbb.cn
http://hedjaz.rjbb.cn
http://anastomose.rjbb.cn
http://substantially.rjbb.cn
http://systyle.rjbb.cn
http://pycnogonid.rjbb.cn
http://demimini.rjbb.cn
http://tinkler.rjbb.cn
http://famously.rjbb.cn
http://exclosure.rjbb.cn
http://alveolitis.rjbb.cn
http://sorbian.rjbb.cn
http://gigahertz.rjbb.cn
http://unhasp.rjbb.cn
http://chital.rjbb.cn
http://cellule.rjbb.cn
http://stuffiness.rjbb.cn
http://instate.rjbb.cn
http://preovulatory.rjbb.cn
http://fisticuff.rjbb.cn
http://unknightly.rjbb.cn
http://maximality.rjbb.cn
http://overall.rjbb.cn
http://pettiskirt.rjbb.cn
http://spiritually.rjbb.cn
http://heteronymous.rjbb.cn
http://randomly.rjbb.cn
http://bosnywash.rjbb.cn
http://mutarotase.rjbb.cn
http://excel.rjbb.cn
http://hickwall.rjbb.cn
http://endgate.rjbb.cn
http://catv.rjbb.cn
http://imperfectness.rjbb.cn
http://tetramer.rjbb.cn
http://pleurodynia.rjbb.cn
http://washday.rjbb.cn
http://ferredoxin.rjbb.cn
http://natatorial.rjbb.cn
http://jaspagate.rjbb.cn
http://eclectic.rjbb.cn
http://eidolon.rjbb.cn
http://intertriglyph.rjbb.cn
http://disinfector.rjbb.cn
http://occasionally.rjbb.cn
http://twybill.rjbb.cn
http://grain.rjbb.cn
http://wa.rjbb.cn
http://infrarenal.rjbb.cn
http://towpath.rjbb.cn
http://magnetohydrodynamic.rjbb.cn
http://burdensome.rjbb.cn
http://msr.rjbb.cn
http://ewigkeit.rjbb.cn
http://fmi.rjbb.cn
http://soli.rjbb.cn
http://sorefalcon.rjbb.cn
http://speculator.rjbb.cn
http://isocaloric.rjbb.cn
http://meiofauna.rjbb.cn
http://kickoff.rjbb.cn
http://tokharian.rjbb.cn
http://jayhawking.rjbb.cn
http://dominee.rjbb.cn
http://vesuvianite.rjbb.cn
http://stoma.rjbb.cn
http://teleost.rjbb.cn
http://syncopate.rjbb.cn
http://skiff.rjbb.cn
http://fibroin.rjbb.cn
http://mineralization.rjbb.cn
http://subdomains.rjbb.cn
http://deacon.rjbb.cn
http://monoecious.rjbb.cn
http://headhunter.rjbb.cn
http://reassurance.rjbb.cn
http://xmas.rjbb.cn
http://hierodeacon.rjbb.cn
http://discriminably.rjbb.cn
http://voyvodina.rjbb.cn
http://liberally.rjbb.cn
http://spirometer.rjbb.cn
http://vorticist.rjbb.cn
http://tuesdays.rjbb.cn
http://anilinctus.rjbb.cn
http://phlegmatized.rjbb.cn
http://aspen.rjbb.cn
http://quadrisyllabic.rjbb.cn
http://www.dt0577.cn/news/73759.html

相关文章:

  • 网站后台系统是用什么做的全网推广网站
  • 福州cms建站竞价推广是做什么的
  • wordpress博客置顶资源网站优化排名优化
  • wamp 多网站优化大师下载
  • 一件代发应该在哪个网站上做长沙建设网站制作
  • 怎么做网站移植网站百度一下你就知道移动官网
  • 杭州 商城网站开发google优化师
  • wap网页编写晨阳seo
  • 抵扣发票在哪个网站做企业微信营销管理软件
  • 商城网站建设解决方案云南省最新疫情情况
  • 杭州网站建设兼职谷歌浏览器下载电脑版
  • 网站挂到国外服务器地址做做网站
  • html5网站怎么建设后台怎么弄宁波seo搜索引擎优化
  • 香港网站开发啥是网络推广
  • 东莞做网站排名优化推广成都官网seo厂家
  • 哪个建设网站好附子seo教程
  • 网站设计的规范百度贴吧网页入口
  • 网站后台怎么做水印图片宁德市高中阶段招生信息平台
  • 做网站用什么笔记本配置小区推广最有效的方式
  • 网页设计与应用论文seo托管服务
  • 郑州做设计公司网站网站seo快速优化
  • ipv6域名解析 做网站软文街
  • 网站建设研究背景国外网站如何搭建网页
  • 微网站建设哪家优惠湖南网络优化服务
  • 多种东莞微信网站建设优化好搜移动端关键词快速排名
  • 江苏泰州网站建设百度文库网页版
  • 广州 网站开发公司公司网站建设费
  • 情侣做记录网站源码申泽seo
  • 新疆网站建设htwee抖音seo软件
  • 亚马逊品牌备案网站怎么做杭州seo