【发布时间】:2019-02-16 05:48:56
【问题描述】:
我目前遇到无法解决的问题。我在 JDeveloper 中有一个项目,使用 ADF。 当模型层某处发生异常(可抛出)时,我无法在视图层中捕获它。 让我更好地解释一下:
在视图中,我有 Transaction.java
public void save(){
try{
Boolean res= (Boolean) context.get("res"); //value obtained from front-end
OperationBinding op = this.getBindings().getOperationBinding("methodThatThrowsException");
op.getParamsMap().put("res", res);
op.execute();//line that should throw exception
}catch(ClassCastException cce){
showMessage(cce.getMessage()); //pop up with a description of the exception
}
然后,在模型层:
public void methodThatThrowsException(Boolean res) throws ClassCastException {
try{
Object obj = res;
Integer badCoding = (Integer) obj; //line that throws exception
}catch(ClassCastException e){
//clean-up code
}
}
methodThatThrowsException 会抛出一个ClassCastException 但它不会被save 方法捕获。
我不知道怎么了。我什至尝试在op.execute(); 之后添加save,但失败了
if(!op.getErrors().isEmpty()){
for(Throwable t : op.getErrors()){
if (t instanceof Exception){
Exception e = (Exception) t;
if (e instanceof RuntimeException)
RuntimeException re = (RuntimeException) e;
if(re instanceof ClassCastException)
throw t;
}
}
但是通过这种可怕的解决方法,t 永远不会被抛出,因为它是 JBOException,而不是在 View 层上时的 ClassCastException。
我能做什么?任何建议现在都对我有用。提前致谢。
【问题讨论】:
标签: exception-handling ejb oracle-adf throw n-tier-architecture