我应该在 if-else 块中引发异常吗?
2022-09-01 06:24:54
代码如下:
public Response getABC(Request request) throws Exception {
Response res = new Response();
try {
if (request.someProperty == 1) {
// business logic
} else {
throw new Exception("xxxx");
}
} catch (Exception e) {
res.setMessage(e.getMessage); // I think this is weird
}
return res;
}
此程序工作正常。我认为它应该重新设计,但如何重新设计呢?