【发布时间】:2019-03-11 13:18:15
【问题描述】:
我有一些与 redis 对话以存储数据的十个 API。
目前它正在抛出嵌套异常,所以我做了如下处理嵌套异常。
@Override
public boolean delMyStatus(String key) {
try{
return redisTemplate.delete(key);
}
catch (Exception e){
if(e.getCause() != null && e.getCause().getCause() instanceof RedisException) {
RedisException ex = (RedisException)e.getCause().getCause();
log.error("RedisException " + ex.getMessage());
/* Do some action*/
} else {
throw new IllegalStateException("...");
}
}
return false;
}
但是我不想对redis dao的所有API都这样做,有没有更好的方法来处理异常。
【问题讨论】:
-
catch (RedisException e){}? -
catch (RedisException e){ log.error("RedisException " + ex.getMessage()); } catch (Exception e){ log.error("Exception " + ex.getMessage()); } 这总是去异常块
标签: spring spring-boot exception