To my understanding following code should print 0
as output because stack is full and it should get out of method immediately.
However when I ran the following code it is printing 100
for first case and prints 1
for second case:
class ErrorAndException {
public static int callStackOverflow() {
try {
callStackOverflow();
return 100;
} catch (Error e) {
System.out.println(e);
return 0;
} finally {
}
}
public static void main(String[] args) {
System.out.println(callStackOverflow());
}
}
Case - 2
class ErrorAndException {
public static int callStackOverflow() {
try {
callStackOverflow();
return 100;
} catch (Error e) {
System.out.println(e);
return 0;
} finally {
return 1
}
}
public static void main(String[] args) {
System.out.println(callStackOverflow());
}
}
Please help me understand this behavior.