zoukankan      html  css  js  c++  java
  • try catch throw在编程里面的应用

    我们可以在try里面写代码,在一些异常情况下我们throw new Exception("不存在此挂号预约");

    这样在catch (Exception e)里面我们就可以获取异常信息并作相应的返回信号

    public Map<String, Object> PUTGHYSQX(Map<String, Object> reqMap) {
            Map<String, Object> resultMap = new HashMap<String, Object>();
            try {
                resultMap.put("code", "0");
                resultMap.put("msg", "SUCCESS");
                String shxh = CommUtil.getStringVal(reqMap, "shxh");
                if (CommUtil.checkNull(shxh)) {
                    throw new Exception("锁号序号shxh不能为空!");
                }
                String patid = CommUtil.getStringValNull(reqMap, "patid");
                if (CommUtil.checkNull(patid)) {
                    throw new Exception("门诊patid不能为空!");
                }
                List<Map> ghyy = queryGHYY(new HashMap() {
                    {
                        put("ORDERID", shxh);
                    }
                });
                if (ghyy.size() == 0) {
                    throw new Exception("不存在此挂号预约");
                }    
                if (CommUtil.getIntVal(ghyy.get(0), "F_ZFZT") == 1) {
                    throw new Exception("此挂号预约已支付,不能取消");
                }
                if (CommUtil.getIntVal(ghyy.get(0), "F_HasGH") == 1) {
                    throw new Exception("此挂号预约已挂号,不能取消");
                }
                if (CommUtil.getIntVal(ghyy.get(0), "F_ISTY") == 1) {
                    throw new Exception("此挂号预约已退约");
                }
                updateTable(Constants.MZ_GHYY, new HashMap(){
                    {
                        put("ORDERID", shxh);
                    }
                }, new HashMap(){
                    {
                        put("F_ISTY", 1);
                    }
                });
                subYSSYHYHZ(ghyy.get(0).get("KSBM").toString(),
                        ghyy.get(0).get("YS").toString(),
                        Integer.parseInt(ghyy.get(0).get("RQ").toString()),
                        Integer.parseInt(ghyy.get(0).get("APM").toString()));
                subYSSYHYMX(ghyy.get(0).get("KSBM").toString(),
                        ghyy.get(0).get("YS").toString(),
                        Integer.parseInt(ghyy.get(0).get("RQ").toString()),
                        Integer.parseInt(ghyy.get(0).get("APM").toString()),
                        ghyy.get(0).get("SJD").toString());
            } catch (Exception e) {
                resultMap.put("code", "-1");
                resultMap.put("msg", "FAIL");
                resultMap.put("result", e.getMessage());
                getLogger().error(e.getMessage());
            }
            return resultMap;
        }
  • 相关阅读:
    【BZOJ】4636: 蒟蒻的数列
    BZOJ1878 [SDOI2009]HH的项链
    【网络流24题----02】太空飞行计划
    【网络流24题----03】Air Raid最小路径覆盖
    【网络流24题----01】飞行员配对方案问题
    素数判定(米勒测试定理-费马小定理+快速乘)
    一堆模板(丑陋0.0)------数据结构
    丑数(USACO)
    NOI[2001]食物链
    关于Tarjan(2)
  • 原文地址:https://www.cnblogs.com/luzhanshi/p/13167710.html
Copyright © 2011-2022 走看看