如何在Java中处理StackOverflowError? [英] How to handle StackOverflowError in Java?

查看:279
本文介绍了如何在Java中处理StackOverflowError?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

我在'你不能确定你的意思是用句柄。



你一定能抓住这个错误:

  public class Example {
public static void endless(){
endless();
}

public static void main(String args []){
try {
无尽();
} catch(StackOverflowError t){
//更一般:catch(错误t)
//任何东西:catch(Throwable t)
System.out.println(catch + T);
t.printStackTrace();
}
System.out.println(之后的错误...);
}
}

但这很可能是一个坏主意,除非你知道你在做什么。


How to handle StackOverflowError in Java ?

解决方案

I'm not sure what you mean with "handle".

You can certainly catch that error:

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...");
    }
}

but that is most likely a bad idea, unless you know exactly what you are doing.

这篇关于如何在Java中处理StackOverflowError?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆