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;
        }
  • 相关阅读:
    <html>
    poj 2676 Sudoku
    百亿互金平台救火故事
    Retrofit三步理解之中的一个 ------------------ Retrofit的简单使用总结
    精简版—愤慨的小鸟
    POJ 1095 Trees Made to Order
    Android Studio 错误: 非法字符: &#39;ufeff&#39; 解决方式|错误: 须要class, interface或enum
    使用CodePush实时更新 React Native 和 Cordova 应用
    获取url地址参数
    利用jQuery 通用文件导出前端实现,MVC文件导出
  • 原文地址:https://www.cnblogs.com/luzhanshi/p/13167710.html
Copyright © 2011-2022 走看看