【发布时间】:2021-12-13 05:49:01
【问题描述】:
我当前的代码块返回如下异常:
Exception occurred in API invocation A1-123 Fatal error
Caused by: A9-001 ColName is not found in TableName
但我想...
- 摆脱
A1 Exception - 直接显示
A9 Exception - 在
Caused by中不显示A9 Exception
如何使异常看起来像这样?
Exception occurred in API invocation A9-001 ColName is not found in TableName
<no Caused by clause>
这是我的示例代码:
public Sample Method (Input input) throws AException
{
con = getSQLConnection();
try{
//do something
if(x==null){
throw new AException(A9ErrorMessages.A9_ERROR_FROM_TABLE, new String [] { "ColName", "TableName"});
}
}
catch (Exception e){
logger().error(e);
throw new AException(e);
}
finally{
if(con!=null){
try{
con.close();
}
catch(Exception e){
logger().error(e);
throw new AException(e);
}
}
}
}
如果是这样的话,它会起作用吗:
try{
//do something
}
catch (Exception e){
logger().error(e);
throw new AException(A9ErrorMessages.A9_ERROR_FROM_TABLE, new String [] { "ColName", "TableName"});
}
catch (Exception e){
logger().error(e);
throw new AException(e);
}
【问题讨论】:
标签: java api exception error-handling try-catch