本文介绍了无抛出VirtualMachineError保证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从C ++开始使用Java。在C ++世界中,我们注意异常安全,并注意,mutator可以在mutator本身抛出的异常或它委托给它的方法(最小,强,无抛出)时提供不同的保证。实现具有强大异常保证的方法需要保证一些基本操作永远不会抛出异常。 JLS声明哪些操作可以抛出哪种异常,但 VirtualMachineError 错误会出现问题。请参阅:

因此在Java中无法保证 VirtualMachineError 例外。所有异常保证必须符合......但如果抛出 VirtualMachineError 则不受限制。这是Java与C ++不同的方式之一。

In Java therefore no exception guarantees can be made with respect to VirtualMachineError exceptions. All exception guarantees must be subject to the qualification "... but not if a VirtualMachineError is thrown". This is one of the ways in which Java is different from C++.

这也表明捕获 VirtualMachineError没有多大意义异常,因为程序处于未定义状态(如果已抛出)。不幸的是,包括 OutOfMemoryError 例外。不幸的是,因为如果其中一个任务失败,因为它需要太多内存,我们可能会继续执行其他任务。

This also suggests that there is not much point in catching a VirtualMachineError exception, because the program is in an undefined state if one has been thrown. That unfortunately includes OutOfMemoryError exceptions. Unfortunate, because if one of several tasks fails because it needs too much memory we might want to continue with the other tasks.

这篇关于无抛出VirtualMachineError保证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-12 10:00