【发布时间】:2012-11-27 21:01:14
【问题描述】:
我是 Java 新手。我创建此代码是为了检查输入字段中的字符串或数字。
try {
int x = Integer.parseInt(value.toString());
} catch (NumberFormatException nFE) {
// If this is a string send error message
throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,
" " + findValue + " must be number!", null));
}
如何创建相同的号码检查但只使用 if(){} 而不使用 try-catch?
【问题讨论】:
-
你为什么不想要try/catch?你已经在使用异常了。
标签: java exception-handling int validation