For each program tell please, would number of method's calls be infinite or final and explain why. These are examples like from Bloch - Java Puzzlers #45
1)
public static void main(String[] args)
{
try
{
main(args);
}
catch(StackOverflowError e)
{
main(args);
}
}
2)
public static void main(String[] args)
{
try
{
main(args);
}
catch(StackOverflowError e)
{
main(args);
}
finally
{
main(args);
}
}
There is a point I want to figure out. For example, the depth of Stack in JVM is 1024. We run this program, method Main is called 1024 times then it happens StackOverflowError and we go first time into catch block where method main is called again. So, on which level of depth are we now? 1024? 1023? 1025?? or first stack is filled and then the other stack is created and we start from 0? how it works? Will we even be in block finally in second example?