举例:
throw new LifeCircleException(
HttpStatus.INTERNAL_SERVER_ERROR,
"SAMPLE NOT EXIST", "样例查询出错");
1、项目中代码的原型
throw new LifeCircleException(HttpStatus.INTERNAL_SERVER_ERROR,
"LC/PT_CODE_IS_NOT_EXIST", //问题提醒
code + ":不是合法的PT维度");` //问题的具体原因
2、数据库操作用Repository的时候要用try--catch包裹。异常的表示为
try {
if (isQuesRepository(resType)) {
commonServiceHelper.saveContributeToQuesDB(contribute);
} else {
contributeRepository.add(contribute);
}
} catch (EspStoreException e) {
throw new LifeCircleException(
HttpStatus.INTERNAL_SERVER_ERROR,
LifeCircleErrorMessageMapper.StoreSdkFail
.getCode(), e.getMessage());
}
3、日期转换出问题的时候用
private boolean isValidDate(String str) {
boolean convertSuccess = true;
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
format.setLenient(false);
try {
format.parse(str);
} catch (java.text.ParseException e) {
throw new LifeCircleException(HttpStatus.INTERNAL_SERVER_ERROR,
LifeCircleErrorMessageMapper.DateFormatFail);
}
return convertSuccess;
}