gpt4 book ai didi

java - 如何在 JAVA 中的 diff 原因上打印相同 NumberFormatException 的 diff 消息?

转载 作者:太空宇宙 更新时间:2023-11-04 08:39:56 26 4
gpt4 key购买 nike

如何在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com