为什么Double.parseDouble(null)和Integer.parseInt(null)抛出不同的异常? [英] Why do Double.parseDouble(null) and Integer.parseInt(null) throw different exceptions?

查看:3392
本文介绍了为什么Double.parseDouble(null)和Integer.parseInt(null)抛出不同的异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么Double.parseDouble(null)和Integer.parseInt(null)抛出不同的异常?



这是一个历史事故还是故意的?文档清楚地说明了 Double.parseDouble(...) ,一个用于 Integer.parseInt() ,但似乎不一致:

  Integer.parseInt(null); // throws java.lang.NumberFormatException:null 

然而

  Double.parseDouble(null); // throws java.lang.NullPointerException 


解决方案


希望抛出相同的异常为null是合理的;然而,这些api是非常老的,可能无法在这一点上改变。


And:


由于异常行为在JavaDoc中是长期存在且指定的,所以现在更改方法的行为是不切实际的。关闭,不会修复。


取自:错误报告:Integer.parseInt()和Double.parseDouble()在null上抛出不同的异常



像其他人一样说:这可能是由不同的作者制作的。


Why do Double.parseDouble(null) and Integer.parseInt(null) throw different exceptions?

Is this a historical accident or intentional? The documentation clearly states two types of exceptions for Double.parseDouble(...) and one for Integer.parseInt(), but it seems inconsistent:

Integer.parseInt(null); // throws java.lang.NumberFormatException: null

However

Double.parseDouble(null); // throws java.lang.NullPointerException

解决方案

It is reasonable to expect the same exceptions to be thrown for null; however, these api's are very old and may not be able to be changed at this point.

And:

Since the exception behavior is long-standing and specified in the JavaDoc, it is impractical to change either method's behavior at this time. Closing as will not fix.

As taken from: Bug Report: Integer.parseInt() and Double.parseDouble() throw different exceptions on null.

Like others have stated: It's likely made by different authors.

这篇关于为什么Double.parseDouble(null)和Integer.parseInt(null)抛出不同的异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆