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中的错误,所有的注册都是关闭的.但“资源限制”的情况呢?是否有任何操作由于资源限制而永远不会失败?
解决方法
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 theVirtualMachineError
subclasses
defined below may be thrown at any time during the operation of the
Java virtual machine:
因此在Java中,对于VirtualMachineError异常,不能保证有异常保证.所有异常保证都必须符合资格“…但是如果引发VirtualMachineError则不能”.这是Java与C不同的方式之一.
这也表明,在捕获VirtualMachineError异常时没有太多的意义,因为如果一个被抛出,程序处于未定义的状态.不幸的是包括OutOfMemoryError异常.不幸的是,因为如果几个任务之一失败,因为它需要太多内存,我们可能希望继续执行其他任务.