如何在 JAVA 中的 diff 原因上打印相同 NumberFormatException 的 diff 消息?
try {
int a=Integer.parseInt(aStr);
int b= Integer.parseInt(bStr);
}catch (NumberFormatException ex) {
if ex's cause is from int a;//ex.getCause()=a?
System.out.println("a is not a integer");
if ex's cause is from int b
System.out.println("b is not a integer");
}
最佳答案
try {
final int a = Integer.parseInt(aStr);
} catch (final NumberFormatException ex) {
System.out.println("a is not a integer");
}
try {
final int b = Integer.parseInt(bStr);
} catch (final Exception e) {
System.out.println("b is not a integer");
}
关于java - 如何在 JAVA 中的 diff 原因上打印相同 NumberFormatException 的 diff 消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5564422/