java - 什么是 OutOfMemoryError 异常,如何产生它?

标签 java exception

对于涉及异常处理的家庭作业练习,我需要生成 OutOfMemoryError 异常,以便我可以编写 try-catch 并捕获它:

"13.10 (OutOfMemoryError) Write a program that causes the JVM to throw an OutOfMemoryError and catches and handles this error."

我搜索了 Java API,但在异常列表中找不到有关 OutOfMemoryError 异常的任何内容。什么是 OutOfMemoryError 异常?如何为我的作业生成一个异常?

最佳答案

比创建数百万个对象简单得多(并且保证有效):

public static void throwOomE() {
    throw new well, you can just search for the rest of the answer
}

关于java - 什么是 OutOfMemoryError 异常,如何产生它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9814664/

相关文章:

java - 线程 "main"java.security.AccessControlException : access denied (java. util.PropertyPermission * 读、写中的异常)

java - org.openqa.selenium.UnhandledAlertException : unexpected alert open

java - 如何将String设置为static int?

java - react-native运行android无法正常工作。无法初始化类org.codehaus.groovy.runtime.InvokerHelper

java - 如何将两个 Jtable 合并到第三个 Jtable 中?

java - AppEngine 下载图

java - 您如何断言在 JUnit 测试中抛出了某个异常?

java - 在 log4j 2 中使用 throwable 和参数

c# - 关闭表单时出现异常(线程+调用)

java - 默认情况下将 Component.ouputMarkupId 设置为 false 背后的设计决策是什么?