对于涉及异常处理的家庭作业练习,我需要生成 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/