不幸的是,我无法控制getUserByUserId(String)
. 它的行为方式是如果找到用户则返回一个用户,OntNoObjectExistsException
如果没有找到用户则抛出一个。OntNoObjectExistsException
我的问题是,由于某种原因,当它被抛出时,它没有捕捉到。
此异常的类型层次结构是:OntNoObjectExistsException
-> OntException
-> Exception
-> Throwable
。
public boolean isUserIdAvailable(String userId) {
try {
return super.getUserByUserId(userId) == null;
} catch (OntNoObjectExistsException e){
return true;
} catch (Exception ex) {
appLog.error(ex.getMessage());
}
return false;
}
我尝试了这段代码来测试水域,但问题仍然存在。注意,我在抓Throwable
。
public boolean isUserIdAvailable(String userId) {
try {
return super.getUserByUserId(userId) == null;
} catch (Throwable ex) {
appLog.error(ex.getMessage());
}
return false;
}
这是堆栈跟踪:
com.opennetwork.exception.OntNoObjectExistsException: User not found
at com.bcbst.dsmart.api.WebUser.getUserByUserId(WebUser.java:411)
at com.bcbst.dsmart.api.WebProspectiveMemberBean.isUserIdAvailable(WebProspectiveMemberBean.java:71)
at com.bcbst.dsmart.api.EJSLocalStatelessWebProspectiveMember_ce00ef7b.isUserIdAvailable(EJSLocalStatelessWebProspectiveMember_ce00ef7b.java:120)
at com.bcbst.prospectivememberweb.actions.UsageagreementAction.execute(UsageagreementAction.java:61)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
另请注意,这是 java 1.4。还有一些我现在无法控制的事情。