Java 中 手动抛出异常: throw new Exception("错误信息") 错误信息的获得


当然需要先用try catch捕获,但注意new Exception("")括号里的字符串其实是异常原因,所以获取是要用ex.getCause().getMessage()

 1 int dylist = dyDao.findByHql("from ZcZcsqdy where yxbz = 1 and zcsqId = "+sqId, null).size();
 2                     if(dylist <= 0){
 3 //                        logger.error("未添加任何资产//////////");
 4 //                        return 0;
 5                         throw new Exception("未添加资产,请重新添加");
 6                     }
 7 
 8 
 9 
10 
11 
12 //捕获异常
13 
14 
15 try{
16             processService.doNextFlow(getRequest());
17         }catch(Exception ex){
18             logger.error("error:" + ex.getMessage());
19             ex.printStackTrace();
20             setJsonString("{success:false,info:\""+ ex.getCause().getMessage()+"\"}");
21         }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM