Java – no virtualmachineerror guarantee

I come from C In the C world, we pay attention to exception security and note that mutator can provide different guarantees in the face of exceptions caused by mutator itself or its delegated methods (minimum, strong, not discarded) To implement the method with strong exception protection, we need to ensure that some basic operations will not throw exceptions JLS gives instructions about which operations can throw which exceptions, but the virtualmachineerror error error is a problem Seven point JLS:

JLS no longer describes virtualmachineerror "Internal error" refers to an error in the JVM, so I am not interested in this situation: in the face of an error in the JVM, all registrations are closed But what about "resource constraints"? Are there any operations that will never fail due to resource constraints?

Solution

Seven point Java virtual machine specification:

Therefore, in Java, there is no exception guarantee for virtualmachineerror exceptions All exception guarantees must qualify "... But not if virtualmachineerror is thrown" This is one of the different ways between Java and C

This also shows that there is not much meaning in catching the virtualmachineerror exception, because if an exception is thrown, the program is in an undefined state Unfortunately, the outofmemoryerror exception is included Unfortunately, if one of several tasks fails because it requires too much memory, we may want to continue with other tasks

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>