java – 无掷VirtualMachineError保证

前端之家收集整理的这篇文章主要介绍了java – 无掷VirtualMachineError保证前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我从C来 Java.在C世界中,我们注意异常安全,并注意到,mutator可以提供不同的保证,面对由mutator本身引发的异常或其委托的方法(最小,强,不丢弃).实现具有强大异常保护的方法需要保证一些基本操作不会抛出异常. JLS发出关于哪些操作可以抛出哪些异常的说明,但是VirtualMachineError错误是一个问题.七点 JLS

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

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

解决方法

七点 Java Virtual Machine Specification

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

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

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

猜你在找的Java相关文章