第2个回答 推荐于2018-01-02
比如在dao层类中写了一个可能会执行失败的方法:
捕获异常的代码如下:
public Map<String, Object> remove(int id) {
Map<String, Object> map = new HashMap<String, Object>();
try {
userGroupDao.remove(id);
map.put("isSuccess", true);
} catch (Exception e) {
map.put("isSuccess", false);
map.put("errorMsg", e.getMessage());
}
return map;
}本回答被网友采纳