1. 程式人生 > >java手動丟擲異常並獲取

java手動丟擲異常並獲取

try{

            if(code == null||code.isEmpty()){
                  throw new Exception("CodeIsNull");
            }

}catch(Exception e){

          if("com.alibaba.fastjson.JSONException".equals(e.getClass().getName())){
                resultMap.put("msg", "識別系統自帶的異常 入 空指標異常");
            }
            else if("CodeIsNull".equals(e.getMessage())){
                resultMap.put("msg", "通過自己丟擲的異常資訊來判斷是否是自己控制的異常丟擲");
            }else{
                resultMap.put("msg", "其他異常");
            }
            e.printStackTrace();

}