In the following code, the methods A()
and B()
are recursively calling each other which causes the StackOverFlow
error. After catching this error how does the program continue to its normal flow of executions as the stack is already overflowed and methods C()->D()->E()
needs to be put in the calling stack.
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");
}
}