为什么,在Java运算,溢出或下溢不会抛出一个异常? [英] Why, In Java arithmetic, overflow or underflow will never throw an Exception?

查看:1454
本文介绍了为什么,在Java运算,溢出或下溢不会抛出一个异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java的算术运算,JVM不要扔溢或溢出异常。所以很多时候,我们会遇到意想不到的结果,不知道哪里出了问题。

During Java Arithmetic operation , JVM do not throw Underflow or Overflow Exception. So many time we come across unexpected results and wondering what went wrong.

而在情况.NET技术,我们有溢出和Undeflow例外。

While in case of .NET technology we have Overflow and Undeflow exception.

所以我的问题是,为什么Java的是设计,不要把算术操作过程中此异常

So my question is that , why Java was design not to throw this exception during arithmetic operation

推荐答案

这是有可能的因素的组合:

This was likely a combination of factors:

  1. 在之前的Java大语言中使用未经检查的算术。著名的算法容易出现数值溢出往往占潜在溢出已经不依赖于检测算法。
  2. 在经过​​算术介绍了算法大量使用的算术指令,这将使Java的,在相当不利特别是对于基准显著的开销。
  3. 在一些算法依赖于无声数值溢/下溢。如果被检查的算术运算,重写这些算法可能很快成为不平凡的。
  4. 经过算术没有必要确保安全存储器(相对于其他的JVM检查像空指针和数组边界)。

在.NET虚拟执行环境(现属的ECMA-335标准)介绍了检查,未经检查的算术单独的指令,使其能够独立解决开发者在现代管理语言的工作性能和安全问题。

The .NET virtual execution environment (now part of the ECMA-335 standard) introduced separate instructions for checked and unchecked arithmetic, allowing it to independently address the performance and safety concerns of developers working in modern managed languages.

这篇关于为什么,在Java运算,溢出或下溢不会抛出一个异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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