【发布时间】:2014-02-14 19:32:37
【问题描述】:
我有兴趣检查异常值,如果我将状态设置为特定值,然后想将货币字符串返回/设置为相应的错误,这可能是用户在客户端抛出错误。
/*code snippet */
cr.setName(Name);
cr.setContact(User);
cr.setValue(Value);
cr.setStatus(status);
try
{
currency = (serviceCountry.createCurrencyTicket( cr, null ));
if ( testPattern( currency ) )
{
return currency;
}
}
catch ( Exception e )
{
this.logger.log( Level.WARNING,
"Exception occured while evaluating currency = "
+ currency, params );
}
例如,异常 e 有 response、cause、stackTrace 对象。我想从响应中检索值并将货币设置为特定的错误。像
catch ( Exception e )
{
if ( e.getClass().getName().getStatus() == 2 )
{
currency = 'ERROR';
} else if ( e.getClass().getName().getStatus() == 0 )
{
currency = 'DOWN';
}
}
【问题讨论】:
-
您的问题是什么?您面临什么问题?
-
e.getClass().getName().getStatus()???这是什么意思。 AFIKgetName返回一个字符串,而字符串没有getStatus -
从
Exception开始是不好的做法;您最好先捕获更具体的异常。Exception还捕获未经检查的异常... -
我无法做到这一点 e.getClass().getName().getStatus(),我找不到 getStatus() 方法。
-
@Mad-D 你的函数是否抛出了自定义异常?
标签: java exception object exception-handling try-catch