加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 无掷VirtualMachineError保证

发布时间:2020-12-14 17:43:58 所属栏目:Java 来源:网络整理
导读:我从C来 Java.在C世界中,我们注意异常安全,并注意到,mutator可以提供不同的保证,面对由mutator本身引发的异常或其委托的方法(最小,强,不丢弃).实现具有强大异常保护的方法需要保证一些基本操作不会抛出异常. JLS发出关于哪些操作可以抛出哪些异常的说明,但是
我从C来 Java.在C世界中,我们注意异常安全,并注意到,mutator可以提供不同的保证,面对由mutator本身引发的异常或其委托的方法(最小,强,不丢弃).实现具有强大异常保护的方法需要保证一些基本操作不会抛出异常. JLS发出关于哪些操作可以抛出哪些异常的说明,但是VirtualMachineError错误是一个问题.七点 JLS:

an internal error or resource limitation prevents the Java virtual
machine from implementing the semantics of the Java programming
language; in this case,an instance of a subclass of
VirtualMachineError is thrown.

JLS不再说明VirtualMachineError. “内部错误”是指JVM中的一个错误,所以我对这种情况并不感兴趣:面对JVM中的错误,所有的注册都是关闭的.但“资源限制”的情况呢?是否有任何操作由于资源限制而永远不会失败?

解决方法

七点 Java Virtual Machine Specification:

This specification cannot predict where internal errors or resource
limitations may be encountered and does not mandate precisely when
they can be reported. Thus,any of the VirtualMachineError subclasses
defined below may be thrown at any time during the operation of the
Java virtual machine:

因此在Java中,对于VirtualMachineError异常,不能保证有异常保证.所有异常保证都必须符合资格“…但是如果引发VirtualMachineError则不能”.这是Java与C不同的方式之一.

这也表明,在捕获VirtualMachineError异常时没有太多的意义,因为如果一个被抛出,程序处于未定义的状态.不幸的是包括OutOfMemoryError异常.不幸的是,因为如果几个任务之一失败,因为它需要太多内存,我们可能希望继续执行其他任务.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读