• try-catch+thows异常范围说明


    方式一:

            CatalogPO deleteTarget = null;
            /** 查询是否存在 **/
            deleteTarget = catalogMapper.findByCatalogId(catalogId);
            if (Objects.isNull(deleteTarget)) {
                log.warn("the delete catalog is not existed");
                throw new WhBuCatalogException(HttpStatus.INTERNAL_SERVER_ERROR, ErrorCode.SUFIX_DB_DELETE, "要删除的服务目录不存在");
            }
            /** 判断是不是是预置服务目录 **/
            if (deleteTarget.getPreseted() == 1) {
                log.warn("the preseted catalog is not allow delete");
                throw new WhBuCatalogException(HttpStatus.INTERNAL_SERVER_ERROR, ErrorCode.SUFIX_DB_DELETE, "预置服务目录不允许删除");
            }
            /** 判断服务目录是否有绑定的服务 **/
            Metadata metadata = new Metadata();
            metadata.setFilter(new TreeMap<>());
            metadata.getFilter().put("catalogId", catalogId.toString());
            metadata.setPaginationParam(new PaginationParam(1,1000,1000));
            List<WhBuService> services = catalogMapper.listBindedServices(metadata);
            if (CollectionUtils.isNotEmpty(services)) {
                log.warn("the catalog has bind service is not allow delete");
                throw new WhBuCatalogException(HttpStatus.INTERNAL_SERVER_ERROR, ErrorCode.SUFIX_DB_DELETE, "服务目录绑定有服务不允许删除");
            }
            try {
                List<Long> ids = findCatalogIdAndChildIds(catalogId);
                catalogMapper.deleteCatalogByIds(ids);
                return mapper.map(deleteTarget,CatalogDO.class);
            } catch (Exception e) {
                log.error("delete catalog error,{}", e);
                throw new WhBuCatalogException(HttpStatus.INTERNAL_SERVER_ERROR, ErrorCode.SUFIX_DB_DELETE, "删除服务目录方法失败");
            }

     红色地方抛出异常,则紫色的地方不会继续执行

    方式二:

            CatalogPO deleteTarget = null;
            try {
                /** 查询是否存在 **/
                deleteTarget = catalogMapper.findByCatalogId(catalogId);
                if (Objects.isNull(deleteTarget)) {
                    log.warn("the delete catalog is not existed");
                    throw new WhBuCatalogException(HttpStatus.INTERNAL_SERVER_ERROR, ErrorCode.SUFIX_DB_DELETE, "要删除的服务目录不存在");
                }
                /** 判断是不是是预置服务目录 **/
                if (deleteTarget.getPreseted() == 1) {
                    log.warn("the preseted catalog is not allow delete");
                    throw new WhBuCatalogException(HttpStatus.INTERNAL_SERVER_ERROR, ErrorCode.SUFIX_DB_DELETE, "预置服务目录不允许删除");
                }
                /** 判断服务目录是否有绑定的服务 **/
                Metadata metadata = new Metadata();
                metadata.setFilter(new TreeMap<>());
                metadata.getFilter().put("catalogId", catalogId.toString());
                metadata.setPaginationParam(new PaginationParam(1,1000,1000));
                List<WhBuService> services = catalogMapper.listBindedServices(metadata);
                if (CollectionUtils.isNotEmpty(services)) {
                    log.warn("the catalog has bind service is not allow delete");
                    throw new WhBuCatalogException(HttpStatus.INTERNAL_SERVER_ERROR, ErrorCode.SUFIX_DB_DELETE, "服务目录绑定有服务不允许删除");
                }
            } catch (Exception e) {
                log.error("delete catalog error,{}", e);
            }
            try {
                List<Long> ids = findCatalogIdAndChildIds(catalogId);
                catalogMapper.deleteCatalogByIds(ids);
                return mapper.map(deleteTarget,CatalogDO.class);
            } catch (Exception e) {
                log.error("delete catalog error,{}", e);
                throw new WhBuCatalogException(HttpStatus.INTERNAL_SERVER_ERROR, ErrorCode.SUFIX_DB_DELETE, "删除服务目录方法失败");
            }

    红色地方抛出异常,则紫色的地方还会继续执行

  • 相关阅读:
    用bash脚本统计代码行数
    Winform应用程序实现通用消息窗口
    文件管理工具“三剑客” #Everything #SpaceSniffer #Clover
    Jenkins pipeline:pipeline 语法详解
    Android studio安装教程
    恶意代码分析实战 shellcode分析 lab 191 192 193 整体来说 对汇编代码的分析要求较高 因为没法直接反编译为C代码看
    恶意代码分析实战 加壳与脱壳 lab 181 182 183 184 185 手动脱壳和自动脱壳操作
    恶意代码分析实战 IDA分析 lab 73 一个通过感染主机exe 修改kernel.dll为恶意dll的后门程序 要做清理的话 是很难的!
    恶意代码分析实战 隐蔽的恶意代码启动 lab121 122 123 124 进程注入、进程替换、hook procmon监控os api调用不行 数据分析还是要sysmon
    恶意代码分析实战 ollydbg使用来了 Lab 91 92 93
  • 原文地址:https://www.cnblogs.com/boshen-hzb/p/9057159.html
Copyright © 2020-2023  润新知