Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
此java程序如何处理StackOverFlow错误并继续正常执行流_Java_Exception - Fatal编程技术网

此java程序如何处理StackOverFlow错误并继续正常执行流

此java程序如何处理StackOverFlow错误并继续正常执行流,java,exception,Java,Exception,在下面的代码中,方法A()和B()彼此递归调用,从而导致StackOverFlow错误。捕获此错误后,由于堆栈已溢出,程序如何继续其正常执行流,并且需要将方法C()->D()->E()放入调用堆栈中 package staticTryOuts; class Test { public static void main(String[] args) { try { A(); }catch(Error e) { System

在下面的代码中,方法
A()
B()
彼此递归调用,从而导致
StackOverFlow
错误。捕获此错误后,由于堆栈已溢出,程序如何继续其正常执行流,并且需要将方法
C()->D()->E()
放入调用堆栈中

package staticTryOuts;

class Test
{
    public static void main(String[] args) {
       try {
        A();
       }catch(Error e) {
           System.out.println(e);
       }
        System.out.println("Hello");
        C();

    }

    static void A() {
        System.out.println("Hello from A");

        B();
    }
    static void B() {
        System.out.println("Hello from B");

        A();
    }
    static void C() {
        System.out.println("Hello World from c.");
        D();
    }
    static void D() {
        System.out.println("Hello world from D");
        E();
    }
    static void E() {
        System.out.println("Hello world from E");

    }
}

抛出的异常意味着它会传播回堆栈,并在运行时展开和清除堆栈帧。当异常返回到最顶部的
catch
块时,堆栈基本上再次为空,并且有空间用于
C
D
E
的方法调用的附加堆栈帧