如果新的失败怎么办?

编程入门 行业动态 更新时间:2024-10-28 08:27:43
本文介绍了如果新的失败怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在C ++和C#中,当新的无法分配内存时,它会抛出异常。

In C++ and C# when new not able to allocate enought memory it throws exception.

我找不到有关Java中新行为的任何信息。 那么如果新的Java失败(内存不足)会发生什么?

I couldn't find any information about new's behavior in Java. So what will happen if new fails in Java (not enough memory)?

推荐答案

假设具体意味着内存分配失败,那么它应抛出 的OutOfMemoryError

Assuming you specifically mean failure of the memory allocation, then it should throw OutOfMemoryError

当Java虚拟机因内存不足而无法分配对象时抛出,垃圾收集器不再提供更多内存。

Thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector.

与错误的所有子类一样,它通常是不可恢复的条件,即使技术上你可以抓住它:

Like all subclasses of Error, it's usually a non-recoverable condition, even if technically you can catch it:

错误是Throwable的一个子类,表明合理的应用程序存在严重问题不应该试图抓住。大多数此类错误都是异常情况。 ThreadDeath错误,虽然是正常条件,但也是Error的子类,因为大多数应用程序不应该尝试捕获它。

An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions. The ThreadDeath error, though a "normal" condition, is also a subclass of Error because most applications should not try to catch it.

不需要声明方法它的throws子句可能在方法执行期间抛出但未捕获的任何子类Error,因为这些错误是不应该发生的异常情况。

A method is not required to declare in its throws clause any subclasses of Error that might be thrown during the execution of the method but not caught, since these errors are abnormal conditions that should never occur.

更多推荐

如果新的失败怎么办?

本文发布于:2023-07-09 14:53:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1087120.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!