我该如何处理StackOverflowError
在Java 中?
最佳答案
我不确定你所说的“处理”是什么意思。
您当然可以捕获该错误:
public class Example {
public static void endless() {
endless();
}
public static void main(String args[]) {
try {
endless();
} catch(StackOverflowError t) {
// more general: catch(Error t)
// anything: catch(Throwable t)
System.out.println("Caught "+t);
t.printStackTrace();
}
System.out.println("After the error...");
}
}
但这很可能是一个坏主意,除非您确切地知道自己在做什么。
关于java - 如何处理 Java 中的 StackOverflowError?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56796238/