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

标签 java exception

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

相关文章:

java - 将 GridView 转换为一行

java - Eclipselink 生活在过去,DDL 不反射(reflect)实体

java - 从 2 字节大端读取 16 位整数

java - 程序打印 1-100 素数并对给定范围内的合数抛出异常

.NET "Send error report to [me]"

asp.net - 来自 asp.net 应用程序的奇怪的未处理异常 - View 状态 MAC 验证失败

java - Thymeleaf 说 Model 属性为 null

java - 为什么 hibernate 将 HibernateException 更改为(未检查的)RuntimeException

java - 在Java中尝试异常,try/catch block 和单例

java - 使用 Comparable 的 Android java 自定义排序